使用python和深度学习实现中译英,最佳实践

在这里插入图片描述

Chinese: 这是一张宣传儿童节特辑音乐汇演的海报。海报的背景是白色的,上面有绿色的树叶和几只彩色的蝴蝶,营造出一种清新自然的氛围。海报的顶部用大号字体写着“精彩音乐汇”四个字,下方是“儿童节特辑”几个字,表明这是一个专门为儿童节准备的音乐活动。

海报中间部分列出了活动的时间和日期,分别是6月1日的06:53、12:19和19:30。接下来是一系列的歌曲名称和演唱者或表演者的名字。这些歌曲包括《青春修炼手册》、《蓝精灵·别看我只是一只羊》、《倍儿爽》等,演唱者或表演者有TFBOYS、邓文怡、大张伟、周华健、吴子安等。

海报的底部有一个红色的标志,上面写着“CCTV音乐”,表明这个活动可能与中央电视台音乐频道有关。整体来看,这张海报设计简洁明了,信息清晰,适合吸引儿童和家长的关注。
English: This is a poster for the children's festival special music show.The background of the poster was white, with green leaves and several coloured butterflies, creating a new natural atmosphere.At the top of the poster, the word “beautiful music” is written in large fonts, followed by the word “children's festival”, indicating that it is a music event specially designed for children's day.

The time and date of the event are listed in the middle of the poster, at 06:53, 12:19 and 19:30 on 1 June, respectively.Next is a series of song names and the names of the singers or performers.These songs include The Manual for Young Men's Studies, Smurfs, Don't look at me as a sheep, Beagle, and others. The singers or performers are TFBOYS, Deng Wenyi, Da Wei, Zhou Huaqiang, Wu Zian, etc.

At the bottom of the poster, there was a red sign with the words “CCTV music”, indicating that the event might be linked to the central television music channel.Overall, the poster was designed in a concise and clear manner, with clear messages that are appropriate to attract the attention of children and parents.
import os
import glob
from easynmt import EasyNMT
from tqdm import tqdm

def translate_files(directory):
    # 初始化 EasyNMT 模型,使用 opus-mt 作为翻译引擎
    model = EasyNMT('opus-mt')

    # 获取目录下所有的 .txt 文件
    files = glob.glob(os.path.join(directory, "*.txt"))
    
    # 使用tqdm创建进度条
    for file_path in tqdm(files, desc="Translating files", unit="file"):
        with open(file_path, 'r', encoding='utf-8') as file:
            chinese_text = file.read()

        # 批量翻译文本
        english_text = model.translate(chinese_text, source_lang='zh', target_lang='en')

        # 打印中文和对应的英文
        print(f"\nFile: {file_path}")
        print("Chinese:", chinese_text)
        print("English:", english_text)
        print("-" * 50)

        # 将英文覆盖写入文件
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(english_text)

# 运行程序
if __name__ == "__main__":
    dataset_dir = "./dataset"
    translate_files(dataset_dir)

我现在半夜2点56写这个,这脚本是做什么的,注释都有,我就不多说了。

很显然,我写的,必出精品,无论是性能取舍,还是质量,都是行业领先的。

不比在线API差劲。

就说这些,希望帮到你,我是人,不是神,我得休息了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Deng_Xian_Shemg

捐助1元钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值