Giter Club home page Giter Club logo

translation-project-based-on-transformers's Introduction

项目概述

这个项目涉及两个主要部分:data.pytransformer.py。其中data.py 包含数据处理模块。 transformer.py包含transformer模型,训练和预测模块。

环境配置

运行pip install -r requirements.txt以安装额外的依赖包。其他都在标准库内。

文件结构

项目的文件结构如下:

  • data.py: 包含数据集下载和数据集读取的模块。
  • transformer.py: 包含Transformer模型的定义,以及训练和预测的模块。
  • data/: 存放数据集的文件夹。
  • README.md: 项目说明文档,你正在阅读的内容。

数据集

项目已经包含了所需的数据集,无需手动下载。数据集文件存放在data/文件夹中。

cn.txt.vocab.tsven.txt.vocab.tsv中每个词语后面的数字表示在训练文本中的出现次数。其中前几个特殊符号的含义如下:

  • <PAD>: 填充符号。
  • <UNK>: 未知符号。
  • <S>: 句子开始。
  • </S>: 句子结束。

cn.txten.txt中每行为一句话,一句话中任何两两相邻的词语和标点符号之间都使用空格分隔,以便于分词。

PS:事实上,这个数据集对于Transformer模型来说太小了。

训练

要训练模型,请执行以下命令:

python transformer.py --cfg train

模型将会保存在model文件夹中,包括best.pthlast.pth,分别为最优权重与最后权重。

预测

要进行预测,请执行以下命令:

python transformer.py --cfg predict

预测的结果将会保存在predict文件夹中。文件名命名格式为模型_predict_第几次预测.txt。文件内容包含原句子与模型翻译的句子。

此处提供一个可用的权重下载:百度网盘 (由于数据集太小,在训练集之外的表现不佳。)

注意训练与预测的具体参数设置都位于transformer.py中。

translation-project-based-on-transformers's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.