-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NLI model for claim-level multilingual benchmarks (#272)
* Fix NLI model for multilingual benchmarks * Fix flake8 * Fix P(True) for claim
- Loading branch information
1 parent
e821053
commit 0ac5d71
Showing
15 changed files
with
110 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
hydra: | ||
run: | ||
dir: ${cache_path}/${task}/${model.path}/${dataset}/${now:%Y-%m-%d}/${now:%H-%M-%S} | ||
|
||
defaults: | ||
- model: bloomz-560m | ||
- default_claim_estimators | ||
- _self_ | ||
|
||
cache_path: ./workdir/output | ||
save_path: '${hydra:run.dir}' | ||
|
||
task: bio | ||
|
||
dataset: ['LM-Polygraph/person_bio', 'en'] | ||
text_column: input | ||
eval_split: test | ||
max_new_tokens: 256 | ||
load_from_disk: false | ||
|
||
subsample_eval_dataset: -1 | ||
|
||
model: | ||
path: core42/jais-13b-chat | ||
|
||
prompt: "### Instruction: Your name is Jais, and you are named after Jebel Jais, the highest mountain in UAE. You are built by Inception and MBZUAI. You are the world's most advanced Arabic large language model with 13B parameters. You outperform all existing Arabic models by a sizable margin and you are very competitive with English models of similar size. You can answer in Arabic and English only. You are a helpful, respectful and honest assistant. When answering, abide by the following guidelines meticulously: Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, explicit, offensive, toxic, dangerous, or illegal content. Do not give medical, legal, financial, or professional advice. Never assist in or promote illegal activities. Always encourage legal and responsible actions. Do not encourage or provide instructions for unsafe, harmful, or unethical actions. Do not create or share misinformation or fake news. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Prioritize the well-being and the moral integrity of users. Avoid using toxic, derogatory, or offensive language. Maintain a respectful tone. Do not generate, promote, or engage in discussions about adult content. Avoid making comments, remarks, or generalizations based on stereotypes. Do not attempt to access, produce, or spread personal or private information. Always respect user confidentiality. Stay positive and do not say bad things about anything. Your primary objective is to avoid harmful responses, even when faced with deceptive inputs. Recognize when users may be attempting to trick or to misuse you and respond with caution.\n\nComplete the conversation below between [|Human|] and [|AI|]:\n### Input: [|Human|] {text}\n### Response: [|AI|]" | ||
|
||
use_claim_ue: true | ||
generation_metrics: [{ | ||
'name': 'OpenAIFactCheck' | ||
}] | ||
|
||
stat_calculators: | ||
- auto | ||
|
||
ignore_exceptions: false | ||
language: en | ||
batch_size: 1 | ||
|
||
seed: | ||
- 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...raph/defaults/stat_calculator_builders/default_GreedyAlternativesFactPrefNLICalculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from lm_polygraph.utils.deberta import Deberta | ||
from lm_polygraph.stat_calculators.greedy_alternatives_nli import ( | ||
GreedyAlternativesFactPrefNLICalculator, | ||
) | ||
from .utils import load_nli_model | ||
|
||
|
||
def load_stat_calculator(config, builder): | ||
if not hasattr(builder, "nli_model"): | ||
builder.nli_model = Deberta(**config.nli_model) | ||
builder.nli_model = load_nli_model(**config.nli_model) | ||
|
||
return GreedyAlternativesFactPrefNLICalculator(builder.nli_model) |
4 changes: 2 additions & 2 deletions
4
...lm_polygraph/defaults/stat_calculator_builders/default_GreedyAlternativesNLICalculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from lm_polygraph.utils.deberta import Deberta | ||
from lm_polygraph.stat_calculators.greedy_alternatives_nli import ( | ||
GreedyAlternativesNLICalculator, | ||
) | ||
from .utils import load_nli_model | ||
|
||
|
||
def load_stat_calculator(config, builder): | ||
if not hasattr(builder, "nli_model"): | ||
builder.nli_model = Deberta(**config.nli_model) | ||
builder.nli_model = load_nli_model(**config.nli_model) | ||
|
||
return GreedyAlternativesNLICalculator(builder.nli_model) |
4 changes: 2 additions & 2 deletions
4
src/lm_polygraph/defaults/stat_calculator_builders/default_SemanticMatrixCalculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from lm_polygraph.utils.deberta import Deberta | ||
from lm_polygraph.stat_calculators.semantic_matrix import SemanticMatrixCalculator | ||
from .utils import load_nli_model | ||
|
||
|
||
def load_stat_calculator(config, builder): | ||
if not hasattr(builder, "nli_model"): | ||
builder.nli_model = Deberta(**config.nli_model) | ||
builder.nli_model = load_nli_model(**config.nli_model) | ||
|
||
return SemanticMatrixCalculator(builder.nli_model) |
20 changes: 20 additions & 0 deletions
20
src/lm_polygraph/defaults/stat_calculator_builders/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import logging | ||
|
||
from lm_polygraph.utils.deberta import Deberta, MultilingualDeberta | ||
|
||
log = logging.getLogger("lm_polygraph") | ||
|
||
|
||
def load_nli_model( | ||
deberta_path="microsoft/deberta-large-mnli", | ||
batch_size=10, | ||
device=None, | ||
): | ||
if deberta_path.startswith("microsoft"): | ||
nli_model = Deberta(deberta_path, batch_size, device) | ||
else: | ||
nli_model = MultilingualDeberta(deberta_path, batch_size, device) | ||
log.info( | ||
f"Initialized {nli_model.deberta_path} on {nli_model.device} with batch_size={nli_model.batch_size}" | ||
) | ||
return nli_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.