Python word translation: Chinese English translation module

Posted by eth0g on Wed, 15 Dec 2021 13:23:32 +0100

Introduction: Tested Chinese English translation module The function of Chinese English translation module. This module only provides limited English word translation function every day.

Key words: Chinese English translation#

 

§ 01 Cifar10 items

   Cifar10 data set is a set of machine vision and depth learning test pictures, which has category labels and English names.

1.1 Cifar10 database

  in Cifar10 The data module includes ten categories of items. The data includes the following four parts:

  • batch_label
  • labels
  • data
  • filenames

  filenames contains a detailed description of each picture.

▲ Figure 1.1 1 items in cifar10

[b'leptodactylus_pentadactylus_s_000004.png', b'camion_s_000148.png', b'tipper_truck_s_001250.png', b'american_elk_s_001521.png', b'station_wagon_s_000293.png', b'coupe_s_001735.png', b'cassowary_s_001300.png', b'cow_pony_s_001168.png', b'sea_boat_s_001584.png', b'tabby_s_001355.png', b'muntjac_s_001000.png', b'arabian_s_001354.png', b'quarter_horse_s_000672.png', b'passerine_s_000343.png', b'camion_s_001895.png']

  what are the Chinese names of these items?

1.2 Chinese English translation module

  in python Chinese English translation module An example of Chinese English translation module is given.

  text translation from one language to another is becoming more and more common in various websites. The python package that helps us do this is called translate.

1.2. 1 module installation

  you can install this package in the following ways. It provides translation in major languages.

1.2. 2. Application method

# encoding: utf-8

from translate import Translator

# The following is a simple sentence from English to Chinese
translator= Translator(to_lang="chinese")
translation = translator.translate("Good night!")
print translation

# Between any two languages, Chinese is translated into English
translator= Translator(from_lang="chinese",to_lang="english")
translation = translator.translate("I miss you")
print translation

1.3 translation of Cifar0 article name

1.3. 1 display Cifar10

plt.figure(figsize=(8,6))
for j in range(3):
    for i in range(5):
        imgdata = d[b'data'][i+j*5]
        imgdata = array(list(zip(imgdata[:1024], imgdata[1024:1024*2], imgdata[1024*2:]))).reshape(32,32,3)
        plt.subplot(3,5, j*5+i+1)
        plt.axis('off')
        plt.imshow(imgdata)

plt.show()

▲ figure 1.3 1. Top 15 pictures in database

1.3. 2 name of reaction article

from headm import *
import translate

strid = 6

strall =tspgetdopstring(strid).replace('[','').replace(']','').replace('b\'','').split(',')
namedim = [s.strip(' ').split('_')[0] for s in strall]

printf(namedim)

#------------------------------------------------------------

translator = translate.Translator(to_lang='chinese')
#------------------------------------------------------------
transdim = []
for s in namedim:
    trans = translator.translate(s)
    printf(trans)
    transdim.append(trans)

[table 1 names of the top 15 items in cifar10 and their translation results]

leptodactyluscamiontipperamericanstation
Hook claw fishCamionDump truckAmerican companystation
coupecassowarycowseatabby
CoupeCrane ostrichCow, cowseaTiger spotted cat
muntjacarabianquarterpasserinecamion
MuntjacarabquarterPasserineCamion
import sys,os,math,time
import matplotlib.pyplot as plt
from numpy import *

strid = 8
strall = tspgetdopstring(strid).split('\r\n')
print(strall)

namedim = strall[0].split('\t')
trandim = strall[1].split('\t')

namedim = list(zip(*([iter(namedim)]*5)))
trandim = list(zip(*([iter(trandim)]*5)))
print(namedim, trandim)

print("")
for n,t in zip(namedim, trandim):
    print(' '.join(n), ' '.join(t))

1.4 application problems

  this translation module can only provide limited word translation services every day.

MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 15 HOURS 19 MINUTES 25 SECONDSVISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE

 

※ test summary ※

  tested Chinese English translation module The function of Chinese English translation module. This module only provides limited English word translation function every day.

■ links to relevant literature:

● relevant chart links:

Topics: Python