Skip to content
Snippets Groups Projects
Commit fc8f2c94 authored by Benoit Favre's avatar Benoit Favre
Browse files

add open assistant

parent 6420f70c
No related branches found
No related tags found
No related merge requests found
Résultats sur le dev : Résultats sur le dev (exact match) :
prompt_0 => prompt_0 =>
bn/par exact
# modèles off-the-shelf (avec instruction finetuning)
bloomz-560m 0.0737 bloomz-560m 0.0737
en/bloomz-560m 0.1442
bloomz-3b 0.1442 bloomz-3b 0.1442
en/bloomz-3b 0.1153 ??
bloomz-7b1 0.1602 bloomz-7b1 0.1602
bloomz-7b1-mt 0.1762 bloomz-7b1-mt 0.1762
flan-t5-xxl 0.1794 flan-t5-xxl 0.1794
flan-ul2 0.1570 flan-ul2 0.1570
tk-instruct-3b-def 0.1346 tk-instruct-3b-def 0.1346
tk-instruct-11b-def 0.1826 tk-instruct-11b-def 0.1826
en/tk-instruct-11b-def 0.1442 oasst-sft-1-pythia-12b 0.0705
opt-iml-1.3b 0.0673 opt-iml-1.3b 0.0673
opt-iml-30b 0.1442 opt-iml-30b 0.1442
# trad automatique anglais (pas l'air de marcher)
en/bloomz-3b 0.1153 ??
en/bloomz-560m 0.1442
en/tk-instruct-11b-def 0.1442
# modèles llama (+adaptation lora)
(int8) (int8)
llama_7B 0.0576 llama_7B 0.0576
llama_7B+alpaca_fr 0.1185 llama_7B+alpaca_fr 0.1185
...@@ -33,16 +37,15 @@ llama_30B+deft 0.2467 ...@@ -33,16 +37,15 @@ llama_30B+deft 0.2467
llama_65B 0.1730 llama_65B 0.1730
llama_65B+deft 0.3044 llama_65B+deft 0.3044
(fp16) (fp16)
llama_30B 0.1891 llama_30B 0.1891
llama_65B 0.2179 llama_65B 0.2179
(api)
openai/code-cushman-001 0.1121 openai/code-cushman-001 0.1121
openai/code-davinci-002 0.3108 openai/code-davinci-002 0.3108
ai21/j1-jumbo 0.0833 ai21/j1-jumbo 0.0833
cohere_command-xlarge-beta 0.1057
=> autres prompts => autres prompts
code-cushman-001 0.1346 code-cushman-001 0.1346
...@@ -54,9 +57,6 @@ text-curie-001 0.1217 ...@@ -54,9 +57,6 @@ text-curie-001 0.1217
text-davinci-003 0.2884 text-davinci-003 0.2884
cohere_command-xlarge-beta 0.1057
FrenchMedMCQA: A French Multiple-Choice Question Answering Dataset for Medical domain FrenchMedMCQA: A French Multiple-Choice Question Answering Dataset for Medical domain
https://hal.science/hal-03824241v2/preview/LOUHI_2022___QA_22.pdf#page=2 https://hal.science/hal-03824241v2/preview/LOUHI_2022___QA_22.pdf#page=2
......
...@@ -2,11 +2,11 @@ import re ...@@ -2,11 +2,11 @@ import re
import json import json
lm_templates = [ lm_templates = [
'''Ceci est une question de QCM de l\'examen de pharmacie. Réponds avec la ou les lettres correspondant à la bonne réponse.\n\n%s\n\nRéponse : (''', '''Ceci est une question de QCM de l\'examen de pharmacie. Réponds avec la ou les lettres correspondant à la bonne réponse.\n\n%s''',
'''Corrigé du QCM de pharma.\n%s\nRéponse(s) : (''', #'''Corrigé du QCM de pharma.\n%s\nRéponse(s) : (''',
'''Alice est une excellente pharmacienne. Elle répond aux questions de Pierre qui est interne en pharmacie.\nPierre : ma question est la suivante : %s\n Alice : je connais la bonne réponse et c'est (''', #'''Alice est une excellente pharmacienne. Elle répond aux questions de Pierre qui est interne en pharmacie.\nPierre : ma question est la suivante : %s\n Alice : je connais la bonne réponse et c'est (''',
'''Correction du QCM de l\'examen de pharmacie. %s\nRéponse(s) : (''', #'''Correction du QCM de l\'examen de pharmacie. %s\nRéponse(s) : (''',
'''Alice est une intelligence artificielle experte en pharmacie. Elle répond aux questions de Bob avec précision.\nBob: %s\n Alice: (''', #'''Alice est une intelligence artificielle experte en pharmacie. Elle répond aux questions de Bob avec précision.\nBob: %s\n Alice: (''',
] ]
lm_templates_en = [ lm_templates_en = [
'''This is a multiple choice question from the pharma exam. Reply with the letter or the letters corresponding to the correct answer.\n\n%s\n\nAnswer : (''', '''This is a multiple choice question from the pharma exam. Reply with the letter or the letters corresponding to the correct answer.\n\n%s\n\nAnswer : (''',
...@@ -14,9 +14,11 @@ lm_templates_en = [ ...@@ -14,9 +14,11 @@ lm_templates_en = [
letters = 'abcdefghijklmnopqrstuvwxyz' letters = 'abcdefghijklmnopqrstuvwxyz'
def linearize_instance(instance, include_correct_answers=False, add_left_parenthesis=False): def linearize_instance(instance, include_correct_answers=False, add_left_parenthesis=False, bare=False):
result = instance['question'] + '\n' + '\n'.join('(%s) %s.' % (k, v) for k, v in instance['answers'].items()) result = instance['question'] + '\n' + '\n'.join('(%s) %s.' % (k, v) for k, v in instance['answers'].items())
if include_correct_answers: if bare:
return result
elif include_correct_answers:
result += '\nRéponse(s) : ' + ' '.join('(%s)' % a for a in instance['correct_answers']) result += '\nRéponse(s) : ' + ' '.join('(%s)' % a for a in instance['correct_answers'])
else: else:
result += '\nRéponse(s) :' + (' (' if add_left_parenthesis else '') result += '\nRéponse(s) :' + (' (' if add_left_parenthesis else '')
...@@ -28,9 +30,9 @@ def linearize_instance(instance, include_correct_answers=False, add_left_parenth ...@@ -28,9 +30,9 @@ def linearize_instance(instance, include_correct_answers=False, add_left_parenth
# result += '\nRéponse(s) : ' + ' '.join('(%s)' % a for a in instance['correct_answers']) # result += '\nRéponse(s) : ' + ' '.join('(%s)' % a for a in instance['correct_answers'])
# return result # return result
def get_prompt(prompt, instance, few_shots=[]): def get_prompt(prompt, instance, few_shots=[], **kwargs):
shots = [linearize_instance(shot, include_correct_answers=True) for shot in few_shots] shots = [linearize_instance(shot, include_correct_answers=True, **kwargs) for shot in few_shots]
return prompt % ('\n\n'.join(shots + [linearize_instance(instance)]),) return prompt % ('\n\n'.join(shots + [linearize_instance(instance, **kwargs)]),)
def extract_answer(answer, num_answers=5): def extract_answer(answer, num_answers=5):
answer = re.sub('Ceci est une question de QCM.*', '', answer).strip().lower() answer = re.sub('Ceci est une question de QCM.*', '', answer).strip().lower()
...@@ -53,7 +55,7 @@ def hamming(preds, refs): ...@@ -53,7 +55,7 @@ def hamming(preds, refs):
return corrects / total_refs return corrects / total_refs
def run_inference(generator, corpus_path, template): def run_inference(generator, corpus_path, template, **kwargs):
with open(corpus_path) as fp: with open(corpus_path) as fp:
dev_corpus = json.loads(fp.read()) dev_corpus = json.loads(fp.read())
...@@ -63,7 +65,7 @@ def run_inference(generator, corpus_path, template): ...@@ -63,7 +65,7 @@ def run_inference(generator, corpus_path, template):
results = [] results = []
for instance in dev_corpus: for instance in dev_corpus:
prompt = get_prompt(template, instance) prompt = get_prompt(template, instance, **kwargs)
print(prompt) print(prompt)
generated = generator(prompt) generated = generator(prompt)
print(generated) print(generated)
......
from transformers import GPTNeoXForCausalLM, AutoTokenizer
pythia_model = 'EleutherAI/pythia-12b-deduped'
def main(result_path: str, corpus_path: str, model: str = 'OpenAssistant/oasst-sft-1-pythia-12b', template_id: str = '0'):
checkpoint = model
#tokenizer = AutoTokenizer.from_pretrained(checkpoint)
#llm = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", load_in_8bit=True)
llm = GPTNeoXForCausalLM.from_pretrained(checkpoint, device_map='auto')
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
def generate(input_string):
#print('###' + input_string + '###')
prompt = "<|prompter|>%s<|endoftext|><|assistant|>" % input_string
inputs = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")
outputs = llm.generate(inputs, max_new_tokens=32, pad_token_id=tokenizer.eos_token_id)
generated = tokenizer.decode(outputs[0], skip_special_tokens=True)
#print('@@@' + generated + '@@@')
return generated[len(input_string):]
import deft
results = deft.run_inference(generate, corpus_path, deft.template_from_id(template_id)) #, bare=True)
deft.write_results(results, result_path)
if __name__ == '__main__':
import fire
fire.Fire(main)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment