غابرييلي سارتي • جرزيجورز شروبالا • مالفينا نسيم • أريانا بيسازا
عملية بيكور المكونة من خطوتين" width="300" style="max-width: 100%;"> أمثلة بيكور" width="500" style="max-width: 100%;">
الملخص: إن تحديد ما إذا كانت النماذج اللغوية يمكنها استخدام المعلومات السياقية بطريقة معقولة للإنسان أمر مهم لضمان اعتمادها بشكل آمن في بيئات العالم الحقيقي. ومع ذلك، فإن الأسئلة المتعلقة بمتى وأي أجزاء من السياق تؤثر على أجيال النماذج يتم التعامل معها عادة بشكل منفصل، وتقتصر تقييمات المعقولية الحالية عمليا على عدد قليل من المعايير المصطنعة. لمعالجة هذه المشكلة، نقدم تقييم معقولية الاعتماد على السياق ( pecore )، وهو إطار قابلية تفسير شامل مصمم لقياس استخدام السياق في أجيال نماذج اللغة. يستفيد نهجنا من العناصر الداخلية للنموذج من أجل (1) تحديد الرموز المميزة الحساسة للسياق بشكل متباين في النصوص التي تم إنشاؤها و(2) ربطها بالإشارات السياقية التي تبرر تنبؤاتها. نحن نستخدم pecore لتحديد مدى معقولية نماذج الترجمة الآلية الواعية بالسياق، ومقارنة مبررات النموذج مع الشروح البشرية عبر العديد من الظواهر على مستوى الخطاب. أخيرًا، نطبق طريقتنا على الأجيال غير المشروحة لتحديد التنبؤات بوساطة السياق وتسليط الضوء على حالات استخدام السياق (غير المعقول) في الترجمات النموذجية.
يحتوي هذا المستودع على نصوص ودفاتر ملاحظات مرتبطة بالورقة البحثية "تحديد مدى معقولية الاعتماد على السياق في الترجمة الآلية العصبية". إذا كنت تستخدم أيًا من المحتويات التالية في عملك، فنطلب منك أن تستشهد بمقالتنا:
@inproceedings { sarti-etal-2023-quantifying ,
title = " Quantifying the Plausibility of Context Reliance in Neural Machine Translation " ,
author = " Sarti, Gabriele and
Chrupa{l}a, Grzegorz and
Nissim, Malvina and
Bisazza, Arianna " ,
booktitle = " The Twelfth International Conference on Learning Representations (ICLR 2024) " ,
month = may,
year = " 2024 " ,
address = " Vienna, Austria " ,
publisher = " OpenReview " ,
url = " https://openreview.net/forum?id=XTHfNGI3zT "
}
نصيحة
يمكنك تجربة pecore من العرض التوضيحي عبر الإنترنت الخاص بنا على Hugging Face Spaces.
في حين أن هذا المستودع ينفذ الوظائف المستخدمة في التقييم التجريبي للورقة المذكورة أعلاه، فإننا نقدم تنفيذ CLI جديد لـ pecore من خلال مكتبة Inseq للتفسير. نحن ننصح الباحثين بشدة بتبني هذا التنفيذ لأنه أكثر قوة وقابلية للتعميم، ويدعم جميع نماذج وحدة فك التشفير فقط ونماذج فك التشفير من مكتبة Huggingface لاكتشاف الاعتماد على سياق الإدخال والإخراج وإسناده. ارجع إلى قسم inseq attribute-context
في ملف Inseq README لمزيد من التفاصيل.
جميع القطع الأثرية الخاصة بالورقة، بما في ذلك النماذج المضبوطة ومجموعات بيانات التدريب/التقييم متوفرة في مجموعة pecore HuggingFace Collection. سيتم توفير العرض التوضيحي قريبًا، ترقبوا ذلك!
يتم تدريب نماذج NMT المدركة للسياق باستخدام البرنامج النصي train_context_aware_mt_model.py
. البرنامج النصي عبارة عن تعديل للملف run_translation_no_trainer.py
الأصلي. يضيف البرنامج النصي الحقول التالية للتدريب على النماذج السياقية:
context_size
: عدد جمل السياق التي سيتم استخدامها للتدريب. القيمة الافتراضية هي 0 (التدريب على مستوى الجملة).
sample_context
: في حالة التعيين، يتم أخذ عينات من حجم السياق لكل مثال من توزيع موحد بين 0 و context_size
(الشامل). إذا لم يتم تمريره وكان context_size
أكبر من 0، فسيكون حجم السياق دائمًا مساويًا لـ context_size
.
context_word_dropout
: الاحتمال بين 0 و1 لإسقاط كلمة من السياق. القيمة الافتراضية هي 0 (لا يوجد تسرب).
use_target_context
: إذا تم تعيينه، فسيتم تضمين السياق أيضًا في النص المترجم لخسارة التدريب. في هذه الحالة، يصبح تنسيق الإخراج للمدخل src_ctx <brk> src
هو tgt_ctx <brk> tgt
. وإلا فإن تنسيق الإخراج هو tgt
(يتم ترجمة src
فقط).
فيما يلي مثال على الضبط الدقيق لنموذج mBART 1 إلى 50 في مجموعة بيانات IWSLT17 المعززة بالسياق مع ما يصل إلى 4 جمل سياقية وتسرب كلمات السياق بنسبة 10%:
accelerate launch scripts/train_context_aware_mt_model.py
--model_name_or_path facebook/mbart-large-50-one-to-many-mmt
--source_lang en_XX
--target_lang fr_XX
--dataset_name gsarti/iwslt2017_context
--dataset_config_name iwslt2017-en-fr
--output_dir outputs/models/iwslt17-mbart50-1toM-ctx4-cwd1-en-fr
--num_beams 5
--max_source_length 512
--max_target_length 128
--num_train_epochs 20
--gradient_accumulation_steps 4
--per_device_train_batch_size 8
--num_warmup_steps 500
--learning_rate 3e-4
--checkpointing_steps epoch
--with_tracking
--report_to tensorboard
--context_size 4
--sample_context
--context_word_dropout 0.1
فيما يلي مثال على مواصلة الضبط الدقيق لنموذج En->Fr OpusMT المدرك للسياق في الجزء التدريبي من SCAT مع ما يصل إلى 4 جمل سياقية وتسرب كلمات السياق بنسبة 10%:
accelerate launch scripts/train_context_aware_mt_model.py
--model_name_or_path context-mt/iwslt17-marian-big-ctx4-cwd1-en-fr
--dataset_name inseq/scat
--dataset_config_name sentences
--output_dir outputs/models/scat-marian-big-ctx4-cwd1-en-fr
--num_beams 5
--max_source_length 512
--max_target_length 128
--num_train_epochs 2
--gradient_accumulation_steps 2
--per_device_train_batch_size 8
--num_warmup_steps 0
--learning_rate 5e-5
--checkpointing_steps 1000
--logging_steps 200
--with_tracking
--report_to tensorboard
--context_size 4
--sample_context
--context_word_dropout 0.1
pecore CLI عبارة عن واجهة سطر أوامر لتشغيل خطوات pecore على نموذج ومجموعة بيانات معينة. يتم تنفيذ واجهة سطر الأوامر (CLI) في البرنامج النصي pecore /cli.py
ويمكن استخدامها كـ pecore -viz
عند تثبيت الحزمة باستخدام pip install -e .
. يدعم التنفيذ الحالي تحديد الأهداف الحساسة للسياق (CTI) وإسناد الإشارات السياقية (CCI) لجميع نماذج التشفير وفك التشفير التي يدعمها إطار عمل Inseq، بما في ذلك النماذج ذات علامات بادئة اللغة (mBART-50، NLLB، M2M100) والنماذج التي تم تدريبها باستخدام علامات السياق الخاصة (على سبيل المثال، مجموعة النماذج الموجودة في منظمة context-mt على HF Hub). يمكن استخدام واجهة سطر الأوامر (CLI) لتشغيل خطوات pecore على نموذج ومثال محددين على النحو التالي:
pecore -viz
--model_name context-mt/scat-marian-small-ctx4-cwd1-en-fr
--attributions_aggregate_fns sum
--model_use_ctx_break
--impute_with_contextless_output
--force_context_aware_output_prefix
--input " Did I mention we stole a cow? A beautiful animal, truly. We brought it to the stable and kept it there for ages.<brk> Sadly, we could not foresee it would disappear. "
المثال أعلاه ينتج المخرجات التالية، ويسلط الضوء بشكل صحيح على الاعتماد على الضمير "il" على الأسماء "البقرة" و"الحيوان" في السياق.
Context with contextual cues (std λ=1.00) followed by output sentence
with context-sensitive target spans (std λ=1.00):
Input context: Did I mention we stole a cow ? A beautiful animal, truly. We brought it to the stable and kept it there for ages.
Input current: Sadly, we could not foresee it would disappear.
Context-aware output: Malheureusement, nous n ' avons pas pu prévoir qu ' il disparaîtrait.
Using ' <brk> ' to separate context and current inputs.
# 1. (CTI |kl_divergence| > 0.14, CCI |saliency| > 0.71)
Contextless output: Malheureusement, nous n ' avons pas pu prévoir qu ' il disparaîtrait.
Current output: Malheureusement, nous n ' avons pas pu prévoir qu ' il(0.412) disparaîtrait.
Input context: Did I mention we stole a cow(1.524) ? A beautiful animal(1.472), truly. We brought it to the stable and kept it
there for ages.
عند استخدام واجهة سطر الأوامر (CLI) لتشغيل نموذج عادي، ستكون هناك حاجة إلى خطوة إضافية لتحديد موضع فاصل السياق في إنشاء النموذج إذا لم يفرض المستخدم المخرجات. فيما يلي مثال باستخدام نموذج mBART-50 العادي من HF Hub:
pecore -viz
--model_name facebook/mbart-large-50-one-to-many-mmt
--input_lang eng --output_lang fra --model_type mbart50-1toM
--impute_with_contextless_output
--force_context_aware_output_prefix
--input " Did I mention we stole a cow? A beautiful animal, truly. We brought it to the stable and kept it there for ages.<brk> Sadly, we could not foresee it would disappear. "
ستتم مطالبة المستخدم بالرسالة التالية:
The following output was generate by the model: J’ai mentionné que nous avons volé une vache, c’est vraiment un beau animal, que nous avons emmené à l’élevage et que nous l’avons gardée pendant des époques. Malheureusement, nous n’avons pas pu prévoir qu’elle disparaîtrait.
Rewrite it here by adding ' <brk> ' wherever appropriate to mark context break:
يمكن للمستخدم بعد ذلك إعادة كتابة الإخراج عن طريق إضافة <brk>
حيثما كان ذلك مناسبًا لوضع علامة على فاصل السياق:
J’ai mentionné que nous avons volé une vache, c’est vraiment un beau animal, que nous avons emmené à l’élevage et que nous l’avons gardée pendant des époques. < brk > Malheureusement, nous n’avons pas pu prévoir qu’elle disparaîtrait.
الناتج النهائي سيكون:
Context with contextual cues (std λ=1.00) followed by output sentence
with context-sensitive target spans (std λ=1.00):
Input context: Did I mention we stole a cow ? A beautiful animal, truly. We brought it to the stable and kept it there for ages.
Input current: Sadly, we could not foresee it would disappear.
Output context: J’ai mentionné que nous avons volé une vache, c’est vraiment un beau animal, que nous avons emmené à l’élevage et que nous l’avons gardée pendant
des époques.
Context-aware output: J’ai mentionné que nous avons volé une vache, c’est vraiment un beau animal, que nous avons emmené à l’élevage et que nous l’avons gardée
pendant des époques. Malheureusement, nous n’avons pas pu prévoir qu’elle disparaîtrait.
Using language tags for model type ' mbart50-1toM ' (eng - > fra).
# 1. (CTI |kl_divergence| > 1.08, CCI |saliency| > 0.00)
Contextless output: Malheureusement, nous n ' avons pas pu prévoir sa disparition.
Current output: Malheureusement, nous n’(3.505)avons pas pu prévoir qu’elle disparaîtrait.
Input context: Did I mention we stole a cow? A beautiful animal, truly. We brought it to the stable(0.002) and kept it there for ages.
Output context: J’(0.004)ai mentionné que nous avons volé une vache, c’(0.002)est vraiment un beau animal, que nous avons emmené à l’(0.003)élevage et que nous
l’(0.007)avons gardée pendant des époques.
في هذه الحالة، نرى النموذج يختار إنشاء الفاصلة العليا المنحنية '
بدلاً من الفاصلة المستقيمة '
المستخدمة افتراضيًا في الإخراج بدون سياق للالتزام بنمط سياق الإخراج، باستخدام هذا الحرف في عدة مناسبات (تم تحديدها على أنها إشارات سياقية بواسطة pecore ) .
في هذا المثال، نستخدم وزن الانتباه للرأس 8 في الطبقة 5 لإسناد الاعتماد على السياق. تم العثور على هذا الرأس تجريبيًا ليتوافق بشكل جيد مع الحدس البشري.
pecore -viz
--model_name context-mt/scat-marian-small-ctx4-cwd1-en-fr
--attributions_aggregate_fns mean mean
--model_use_ctx_break
--impute_with_contextless_output
--force_context_aware_output_prefix
--input " Did I mention we stole a cow? A beautiful animal, truly. We brought it to the stable and kept it there for ages.<brk> Sadly, we could not foresee it would disappear. "
--attribution_method attention
--select_attributions_idx 7 4
python scripts/translate.py
--model_type mbart50-1toM
--model_id mbart50-1toM-scat
--model_name context-mt/scat-mbart50-1toM-ctx4-cwd1-en-fr
--context_size 4
--dataset scat
--context_word_dropout 1
python scripts/translate.py
--model_type marian-big
--model_id marian-big-scat-target
--model_name context-mt/scat-marian-big-target-ctx4-cwd0-en-fr
--context_size 4
--dataset disc_eval_mt
--context_word_dropout 0
--dataset_config anaphora
python scripts/translate.py
--model_type marian-big
--model_id marian-big-scat-target
--model_name context-mt/scat-marian-big-target-ctx4-cwd0-en-fr
--context_size 4
--dataset disc_eval_mt
--context_word_dropout 0
--dataset_config lexical-choice
python scripts/translate.py
--model_type marian-big
--model_id marian-big-scat
--model_name context-mt/scat-marian-big-ctx4-cwd1-en-fr
--context_size 4
--dataset disc_eval_mt
--context_word_dropout 1
--dataset_config anaphora
python scripts/translate.py
--model_type marian-big
--model_id marian-big-scat
--model_name context-mt/scat-marian-big-ctx4-cwd1-en-fr
--context_size 4
--dataset disc_eval_mt
--context_word_dropout 1
--dataset_config lexical-choice
python scripts/translate.py
--model_type mbart50-1toM
--model_id mbart50-1toM-scat
--model_name context-mt/scat-mbart50-1toM-ctx4-cwd1-en-fr
--context_size 0
--dataset disc_eval_mt
--context_word_dropout 0
--dataset_config lexical-choice
python scripts/evaluate_mt_outputs.py
--filepath outputs/translations/ctx/scat-marian-small-scat-target.txt
--model_id marian-small-scat-target
--dataset scat
--src_lang eng
--tgt_lang fra
--metrics bleu comet accuracy flip
--has_target_context
--max_idx 250
python scripts/evaluate_mt_outputs.py
--filepath outputs/translations/ctx/disc_eval_mt-anaphora-marian-small-scat-target.txt
--model_id marian-small-scat-target
--dataset disc_eval_mt
--src_lang eng
--tgt_lang fra
--metrics bleu comet accuracy flip
--has_target_context
--max_idx 250
python scripts/evaluate_mt_outputs.py
--filepath outputs/translations/ctx/scat-mbart50-1toM-scat.txt
--model_id mbart50-1toM-scat
--dataset scat
--src_lang eng
--tgt_lang fra
--metrics bleu comet accuracy
python scripts/evaluate_mt_outputs.py
--filepath outputs/translations/ctx/scat-mbart50-1toM-scat.txt
--model_id mbart50-1toM-scat
--dataset scat
--src_lang eng
--tgt_lang fra
--metrics comet accuracy
python scripts/generate_examples.py
--dataset scat
--model_name context-mt/scat-marian-small-target-ctx4-cwd0-en-fr
--src_lang eng
--tgt_lang fra
--model_id marian-small-scat-target
--model_type marian-small
--has_context
--has_contrast
--has_target_context
python scripts/generate_examples.py
--dataset scat
--model_name context-mt/scat-mbart50-1toM-target-ctx4-cwd0-en-fr
--src_lang eng
--tgt_lang fra
--model_id mbart50-1toM-scat-target
--model_type mbart50-1toM
--has_context
--has_target_context
--has_contrast
python scripts/generate_examples.py
--dataset disc_eval_mt
--dataset_config anaphora
--model_name context-mt/scat-marian-small-ctx4-cwd1-en-fr
--src_lang eng
--tgt_lang fra
--model_id marian-small-scat
--model_type marian-small
--has_context
--has_contrast
python scripts/generate_examples.py
--dataset scat
--model_name Helsinki-NLP/opus-mt-en-fr
--src_lang eng
--tgt_lang fra
--model_id marian-small
--model_type marian-small
--has_contrast
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-marian-small-scat.tsv
--model_name context-mt/scat-marian-small-ctx4-cwd1-en-fr
--model_type marian-small
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-marian-big-scat.tsv
--model_name context-mt/scat-marian-big-ctx4-cwd1-en-fr
--model_type marian-big
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-mbart50-1toM-scat.tsv
--model_name context-mt/scat-mbart50-1toM-ctx4-cwd1-en-fr
--model_type mbart50-1toM
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-marian-small-scat-target.tsv
--model_name context-mt/scat-marian-small-target-ctx4-cwd0-en-fr
--model_type marian-small
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-marian-big-scat-target.tsv
--model_name context-mt/scat-marian-big-target-ctx4-cwd0-en-fr
--model_type marian-big
python scripts/tag_cti_metrics.py
--examples_path outputs/processed_examples/scat-mbart50-1toM-scat-target.tsv
--model_name context-mt/scat-mbart50-1toM-target-ctx4-cwd0-en-fr
--model_type mbart50-1toM
python scripts/tag_cci_metrics.py
--examples_path outputs/processed_examples/scat-marian-small-scat.tsv
--model_name context-mt/scat-marian-small-ctx4-cwd1-en-fr
--model_type marian-small
python scripts/tag_cci_metrics.py
--examples_path outputs/processed_examples/scat-mbart50-1toM-scat-target.tsv
--model_name context-mt/scat-mbart50-1toM-target-ctx4-cwd0-en-fr
--model_type mbart50-1toM
python scripts/evaluate_tagged_metrics.py
--scores_path outputs/scores/scat-marian-small-scat-cti.tsv
--eval_mode cti
--use_trained_model
python scripts/evaluate_tagged_metrics.py
--scores_path outputs/scores/scat-marian-small-scat-cti.tsv
--eval_mode cti
--average_example_scores
--metrics random pcxmi kl_divergence
--save_preds
python scripts/evaluate_tagged_metrics.py
--scores_path outputs/scores/scat-marian-small-scat-cci.tsv
--eval_mode cci
--example_target_column is_supporting_context
--average_example_scores
--metrics random saliency_contrast_prob_diff attention_default attention_best
python scripts/evaluate_tagged_metrics.py
--scores_path outputs/scores/scat-marian-small-scat-target-cti.tsv
--eval_mode cti
--average_example_scores
--metrics random pcxmi kl_divergence
--save_preds