Github: https://github.com/facebookresearch/end-to-end-negotiator
前書き
これは、 PyTorchのリサーチペーパーDealまたはDealの実装です。 交渉のためのエンドツーエンド学習 Facebook AI Researchによって開発された対話 。
このコードは、自然言語で交渉を行うためにニューラルネットワークを訓練し、自己再生とロールアウトに基づいた計画を強化することを可能にします。
引用
あなたの研究でこのコードを使用したい場合は、引用してください:
@article{lewis2017dealornodeal,
author = {Lewis, Mike and Yarats, Denis and Dauphin, Yann N and Parikh, Devi and Batra, Dhruv},
title = "{Deal or No Deal? End-to-End Learning for Negotiation Dialogues}",
journal = {ArXiv e-prints},
archivePrefix = "arXiv",
eprinttype = {arxiv},
eprint = {1706.05125},
primaryClass = "cs.AI",
keywords = {Computer Science - Artificial Intelligence},
year = 2017,
month = June,
}
データセット
コードと一緒にデータセットをリリースすると、 data/negotiate
下でそのデータセットを見つけることができます。 このデータセットは、2236のユニークなシナリオに基づいて5808個の対話から構成されています。 データ収集について学ぶために、論文の§2.3を見てください。
各ダイアログは、データセット内の2つのトレーニング例に変換され、各エージェントの視点からの完全な会話を示します。 パースペクティブは、入力目標、出力の選択、ステートメントが読み込まれたか書き込まれたかを示す特殊なトークンで異なります。 データ表現の詳細については3.1を参照。
# Perspective of Agent 1
<input> 1 4 4 1 1 2 </input>
<dialogue> THEM: i would like 4 hats and you can have the rest . <eos> YOU: deal <eos> THEM: <selection> </dialogue>
<output> item0=1 item1=0 item2=1 item0=0 item1=4 item2=0 </output>
<partner_input> 1 0 4 2 1 2 </partner_input>
# Perspective of Agent 2
<input> 1 0 4 2 1 2 </input>
<dialogue> YOU: i would like 4 hats and you can have the rest . <eos> THEM: deal <eos> YOU: <selection> </dialogue>
<output> item0=0 item1=4 item2=0 item0=1 item1=0 item2=1 </output>
<partner_input> 1 4 4 1 1 2 </partner_input>
セットアップ
すべてのコードはCentOS Linux 7上のPython 3.0で開発されました。さらにPyTorchとCUDA8を使用しました。
Anacondaを使用することをお勧めします。 作業環境を設定するには、以下の手順に従います。
# Install anaconda
conda create -n py30 python=3 anaconda
# Activate environment
source activate py30
# Install PyTorch
conda install pytorch torchvision cuda80 -c soumith
# Install Visdom if you want to use visualization
pip install visdom
使用法
トレーニング
新しいモデルを訓練するには、 train.py
スクリプトを使用します。 ここでは、GPU上の特定の設定を習得する方法を示します。
python train.py \
--data data/negotiate \
--cuda \
--bsz 16 \
--clip 0.5 \
--decay_every 1 \
--decay_rate 5.0 \
--dropout 0.5 \
--init_range 0.1 \
--lr 1 \
--max_epoch 30 \
--min_lr 0.01 \
--momentum 0.1 \
--nembed_ctx 64 \
--nembed_word 256 \
--nesterov \
--nhid_attn 256 \
--nhid_ctx 64 \
--nhid_lang 128 \
--nhid_sel 256 \
--nhid_strat 128 \
--sel_weight 0.5 \
--model_file sv_model.th
goal-basedインセンティブを持つ事前訓練された監督モデルを洗練するために、 reinforce.py
を次のように使用することができます:
python reinforce.py \
--data data/negotiate \
--cuda \
--bsz 16 \
--clip 1 \
--context_file data/negotiate/selfplay.txt \
--eps 0.0 \
--gamma 0.95 \
--lr 0.5 \
--momentum 0.1 \
--nepoch 4 \
--nesterov \
--ref_text data/negotiate/train.txt \
--rl_clip 1 \
--rl_lr 0.2 \
--score_threshold 6 \
--sv_train_freq 4 \
--temperature 0.5 \
--alice_model sv_model.th \
--bob_model sv_model.th \
--output_model_file rl_model.th
セルフプレイ
相互にネゴシエートする2つの事前トレーニングされたモデルを使用する場合は、 selfplay.py
使用しselfplay.py
。 たとえば、監督されたモデルに対して強化されたモデルを再生させることができます。
python selfplay.py \
--alice_model_file rl_model.th \
--bob_model_file sv_model.th \
--context_file data/negotiate/selfplay.txt \
--temperature 0.5 \
--log_file selfplay.log \
--ref_text data/negotiate/train.txt
selfplay.log
ログファイルには、モデルによって生成された実際の対話だけでなく、いくつかの統計があります。 例えば:
================================================================================
Alice : book=(count:3 value:1) hat=(count:1 value:5) ball=(count:1 value:2)
Bob : book=(count:3 value:1) hat=(count:1 value:1) ball=(count:1 value:6)
--------------------------------------------------------------------------------
Alice : i would like the hat and the ball . <eos>
Bob : i need the ball and the hat <eos>
Alice : i can give you the ball and one book . <eos>
Bob : i can't make a deal without the ball <eos>
Alice : okay then i will take the hat and the ball <eos>
Bob : okay , that's fine . <eos>
Alice : <selection>
Alice : book=0 hat=1 ball=1 book=3 hat=0 ball=0
Bob : book=3 hat=0 ball=0 book=0 hat=1 ball=1
--------------------------------------------------------------------------------
Agreement!
Alice : 7 points
Bob : 3 points
--------------------------------------------------------------------------------
dialog_len=4.47 sent_len=6.93 agree=86.67% advantage=3.14 time=2.069s comb_rew=10.93 alice_rew=6.93 alice_sel=60.00% alice_unique=26 bob_rew=4.00 bob_sel=40.00% bob_unique=25 full_match=0.78
--------------------------------------------------------------------------------
debug: 3 1 1 5 1 2 item0=0 item1=1 item2=1
debug: 3 1 1 1 1 6 item0=3 item1=0 item2=0
================================================================================
ロールアウトを介して計画を実行していずれかのモデルのネゴシエーションパフォーマンスを向上させるには、それぞれ--smart_alice
または--smart_bob
追加します。
python selfplay.py \
--alice_model_file rl_model.th \
--smart_alice \
--bob_model_file sv_model.th \
--context_file data/negotiate/selfplay.txt \
--temperature 0.5 \
--log_file selfplay.log \
--ref_text data/negotiate/train.txt
チャット
chat.py
を使って自分で試して、テキストベースのインターフェースを使ってモデルとネゴシエートすることもできます:
python chat.py \
--model_file rl_model.th \
--smart_ai \
--context_file data/negotiate/selfplay.txt \
--temperature 0.5 \
--ref_text data/negotiate/train.txt
人間のボットとのやりとりの例は、「Alice」というボットがあります。
================================================================================
Dialog 0
--------------------------------------------------------------------------------
Human : book=(count:1 value:2) hat=(count:2 value:2) ball=(count:2 value:2)
Alice : book=(count:1 value:4) hat=(count:2 value:0) ball=(count:2 value:3)
--------------------------------------------------------------------------------
Human : hi i want the hats and the balls
Alice : i will take the balls and book <eos>
Human : no i need the balls
Alice : i will take the balls and book <eos>
Human : i need the balls
Alice : you can have the hats if i get the balls and book <eos>
Human : no i need the balls and you can take the rest
Alice : i will take the balls and 1 book <eos>
Human : no, no balls for you
Alice : ok , you can have two hats and one ball <eos>
Human : ok deal
Alice : <selection>
Human choice: 0 2 1
Human : book=0 hat=2 ball=1
Alice : book=1 hat=0 ball=1
--------------------------------------------------------------------------------
Agreement!
Human : 6 points
Alice : 7 points
--------------------------------------------------------------------------------
dialog_len=12.00 sent_len=7.58 agree=100.00% advantage=-1.00 time=87.341s comb_rew=13.00 human_rew=6.00 human_sel=0.00% human_unique=6 alice_rew=7.00 alice_sel=100.00% alice_unique=5 full_match=0.25
--------------------------------------------------------------------------------
debug: 1 2 2 2 2 2 item0=0 item1=2 item2=1
debug: 1 4 2 0 2 3 item0=1 item1=0 item2=1 item0=0 item1=2 item2=1
================================================================================
ライセンス
このプロジェクトは、CC-NCの下でライセンスされています。詳細については、LICENSEファイルを参照してください。