在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):OpenNMT/OpenNMT-tf开源软件地址(OpenSource Url):https://github.com/OpenNMT/OpenNMT-tf开源编程语言(OpenSource Language):Python 99.1%开源软件介绍(OpenSource Introduction):OpenNMT-tfOpenNMT-tf is a general purpose sequence learning toolkit using TensorFlow 2. While neural machine translation is the main target task, it has been designed to more generally support:
The project is production-oriented and comes with backward compatibility guarantees. Key featuresModular model architectureModels are described with code to allow training custom architectures and overriding default behavior. For example, the following instance defines a sequence to sequence model with 2 concatenated input features, a self-attentional encoder, and an attentional RNN decoder sharing its input and output embeddings: opennmt.models.SequenceToSequence(
source_inputter=opennmt.inputters.ParallelInputter(
[
opennmt.inputters.WordEmbedder(embedding_size=256),
opennmt.inputters.WordEmbedder(embedding_size=256),
],
reducer=opennmt.layers.ConcatReducer(axis=-1),
),
target_inputter=opennmt.inputters.WordEmbedder(embedding_size=512),
encoder=opennmt.encoders.SelfAttentionEncoder(num_layers=6),
decoder=opennmt.decoders.AttentionalRNNDecoder(
num_layers=4,
num_units=512,
attention_mechanism_class=tfa.seq2seq.LuongAttention,
),
share_embeddings=opennmt.models.EmbeddingsSharingLevel.TARGET,
) The
Standard models such as the Transformer are defined in a model catalog and can be used without additional configuration. Find more information about model configuration in the documentation. Full TensorFlow 2 integrationOpenNMT-tf is fully integrated in the TensorFlow 2 ecosystem:
Compatibility with CTranslate2CTranslate2 is an optimized inference engine for OpenNMT models featuring fast CPU and GPU execution, model quantization, parallel translations, dynamic memory usage, interactive decoding, and more! OpenNMT-tf can automatically export models to be used in CTranslate2. Dynamic data pipelineOpenNMT-tf does not require to compile the data before the training. Instead, it can directly read text files and preprocess the data when needed by the training. This allows on-the-fly tokenization and data augmentation by injecting random noise. Model fine-tuningOpenNMT-tf supports model fine-tuning workflows:
Source-target alignmentSequence to sequence models can be trained with guided alignment and alignment information are returned as part of the translation API. OpenNMT-tf also implements most of the techniques commonly used to train and evaluate sequence models, such as:
See the documentation to learn how to use these features. UsageOpenNMT-tf requires:
We recommend installing it with pip install --upgrade pip
pip install OpenNMT-tf See the documentation for more information. Command lineOpenNMT-tf comes with several command line utilities to prepare data, train, and evaluate models. For all tasks involving a model execution, OpenNMT-tf uses a unique entrypoint:
that are passed to the main script:
For more information and examples on how to use OpenNMT-tf, please visit our documentation. LibraryOpenNMT-tf also exposes well-defined and stable APIs, from high-level training utilities to low-level model layers and dataset transformations. For example, the import opennmt
config = {
"model_dir": "/data/wmt-ende/checkpoints/",
"data": {
"source_vocabulary": "/data/wmt-ende/joint-vocab.txt",
"target_vocabulary": "/data/wmt-ende/joint-vocab.txt",
"train_features_file": "/data/wmt-ende/train.en",
"train_labels_file": "/data/wmt-ende/train.de",
"eval_features_file": "/data/wmt-ende/valid.en",
"eval_labels_file": "/data/wmt-ende/valid.de",
}
}
model = opennmt.models.TransformerBase()
runner = opennmt.Runner(model, config, auto_config=True)
runner.train(num_devices=2, with_eval=True) Here is another example using OpenNMT-tf to run efficient beam search with a self-attentional decoder: decoder = opennmt.decoders.SelfAttentionDecoder(num_layers=6, vocab_size=32000)
initial_state = decoder.initial_state(
memory=memory, memory_sequence_length=memory_sequence_length
)
batch_size = tf.shape(memory)[0]
start_ids = tf.fill([batch_size], opennmt.START_OF_SENTENCE_ID)
decoding_result = decoder.dynamic_decode(
target_embedding,
start_ids=start_ids,
initial_state=initial_state,
decoding_strategy=opennmt.utils.BeamSearch(4),
) More examples using OpenNMT-tf as a library can be found online:
For a complete overview of the APIs, see the package documentation. Additional resources |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论