日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Tensor2Tensor 踩坑记录

發布時間:2025/4/16 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tensor2Tensor 踩坑记录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

Tensor2Tensor(Transformer)使用方法

安裝環境

  • 安裝CUDA 9.0 (一定是9.0,不能是9.2)
  • 安裝TensorFlow (現在是1.8)
  • 安裝Tensor2Tensor
  • 開始使用

  • 數據預處理:這一步驟是根據自己任務自己編寫一些預處理的代碼,比如字符串格式化,生成特征向量等操作。
  • 編寫自定義problem:
  • 編寫自定義的problem代碼,一定需要在自定義類名前加裝飾器。(@registry.registry_problem)
  • 自定義problem的類名一定是駝峰式命名,py文件名一定是下劃線式命名,且與類名對應
  • 一定需要繼承父類problem,t2t已經提供用于生成數據的problem,需要自行將自己的問題人腦分類找到對應的父類,主要定義的父類problem有:(運行 t2t-datagen 可以查看到problem list)
  • 一定需要在__init__.py文件里導入自定義problem文件
  • 使用t2t-datagen 將自己預處理后的數據轉為t2t的格式化數據集
  • 運行 t2t-datagen --help 或 t2t-datagen --helpfull
  • 如果自定義problem代碼的輸出格式不正確,則此命令會報錯
  • 注意路徑
  • Eg. cd scripts && t2t-datagen --t2t_usr_dir=./ --data_dir=../train_data --tmp_dir=../tmp_data --problem=my_problem
  • 使用t2t-trainer使用格式化的數據集進行訓練
  • 運行t2t-trainer --help 或 t2t-trainer --helpfull
  • Eg. cd scripts && t2t-trainer --t2t_usr_dir=./ --problem=my_problem --data_dir=../train_data --model=transformer --hparams_set=transformer_base --output_dir=../output --train_steps=20 --eval_steps=100
  • 主要的參數有:

    --eval_steps: Number of steps in evaluation. By default, eval will stop after eval_steps or when it runs through the eval dataset once in full, whichever comes first, so this can be a very large number. (default: '100')

    --output_dir: Base output directory for run. (default: '')

    --t2t_usr_dir: Path to a Python module that will be imported. The __init__.py file should include the necessary imports. The imported files should contain registrations, e.g. @registry.register_model calls, that will then be available to the t2t-trainer.

    --keep_checkpoint_every_n_hours: Number of hours between each checkpoint to be saved. The default value 10,000 hours effectively disables it. (default: '10000') (an integer)

    --keep_checkpoint_max: How many recent checkpoints to keep. (default: '20') (an integer)

    --local_eval_frequency: Save checkpoints and run evaluation every N steps during local training. (default: '1000') (an integer)

    --train_steps: The number of steps to run training for. (default: '250000') (an integer)

    --warm_start_from: Warm start from checkpoint.

    --worker_gpu: How many GPUs to use. (default: '1') (an integer)

  • 使用t2t-decoder對測試集進行預測
  • 如果想使用某一個checkpoint時的結果時,需要將checkpoint文件中的第一行: model_checkpoint_path: “model.ckpt-xxxx” 的最后的序號修改即可
  • Eg. cd scripts && t2t-decoder --t2t_usr_dir=./ --problem=my_problem --data_dir=../train_data --model=transformer --hparams_set=transformer_base --output_dir=../output --decode_hparams=”beam_size=5,alpha=0.6” --decode_from_file=../decode_in/test_in.txt --decode_to_file=../decode_out/test_out.txt
  • 注意路徑
  • 使用t2t-exporter導出訓練模型
  • 分析結果
  • 總結

    以上是生活随笔為你收集整理的Tensor2Tensor 踩坑记录的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。