Views
No views yet
Update February 23 2025: 🔥 BATCHING MODE SUPPORT. See 🌌 Flan-T5 provider for bulk-chain project. Test is available here
1import torch
2from transformers import AutoTokenizer, T5ForConditionalGeneration
3
4# Setup model path.
5model_path = "nicolay-r/flan-t5-tsa-prompt-base"
6# Setup device.
7device = "cuda:0"
8
9model = T5ForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.bfloat16)
10tokenizer = AutoTokenizer.from_pretrained(model_path)
11model.to(device)1def ask(prompt):
2 inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
3 inputs.to(device)
4 output = model.generate(**inputs, temperature=1)
5 return tokenizer.batch_decode(output, skip_special_tokens=True)[0]1# Input sentence.
2sentence = "I would support him"
3# Input target.
4target = "him"
5# output response
6flant5_response = ask(f"What's the attitude of the sentence '{context}', to the target '{target}'?")
7print(f"Author opinion towards `{target}` in `{sentence}` is:\n{flant5_response}")Author opinion towards "him" in "I would support him despite his bad behavior." is: positive
PROMPT mode to the validation data of the RuSentNE-2023 competition for evaluation.1python thor_finetune.py -m "nicolay-r/flan-t5-tsa-prompt-xl" -r "prompt" \
2 -p "What's the attitude of the sentence '{context}', to the target '{target}'?" \
3 -d "rusentne2023" -z -bs 4 -f "./config/config.yaml"positive, negative, neutral),
the behavior in general might be biased to this particular task.train data which was automatically translated into English using GoogleTransAPI.
The initial source of the texts written in Russian, is from the following repository:
https://github.com/dialogue-evaluation/RuSentNE-evaluation
test evaluation data:
https://github.com/dialogue-evaluation/RuSentNE-evaluation/blob/main/final_data.csvpositive and negative classes;positive, negative, and neutral classes;test set after 4 epochs (lines 5-6):1 F1_PN F1_PN0 default mode
20 66.678 73.838 73.838 valid
31 68.019 74.816 74.816 valid
42 67.870 74.688 74.688 valid
53 65.090 72.449 72.449 test
64 65.090 72.449 72.449 test