Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3model_name = "alespalla/distillbert_conv_quality_score"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForSequenceClassification.from_pretrained(model_name)
6
7conversation = '''
8Q: Begin
9A: lol ! do you think it is strange to feel like you have been through life before ?
10Q: Hellow
11A: I don't understand you 🙈. Also, try to guess: i like to ...
12Q: How are you?
13A: make time stop, funny you :)
14Q: What is your name?
15A: jessie. hows your day going ? 😃
16'''
17
18score = model(**tokenizer(conversation, return_tensors='pt')).logits.item()
19print(f"Score: {score}")conv_ai_2 using the following function1
2from datasets import load_dataset
3
4def get_dataset(regression=False):
5
6 db = load_dataset("conv_ai_2")
7
8 def generate_converation(elem):
9 text = ""
10 for idx, txt in enumerate(elem["dialog"]):
11 if idx % 2:
12 text += f"A: {txt['text']}\n"
13 else:
14 text += f"Q: {txt['text']}\n"
15 if regression:
16 return {'text': text, "labels": (elem['eval_score'] - 1)/4}
17 return {'text': text, "labels": elem['eval_score'] - 1}
18
19 db = db.filter(lambda example: example["eval_score"] > 0)
20 db = db.map(generate_converation, remove_columns=db['train'].column_names)
21 db = db['train'].train_test_split(test_size=0.2).shuffle(42)
22
23 return db
24| step | training/loss | validation/loss |
|---|---|---|
| 81 | 0.1020 | 0.0794 |
| 163 | 0.0800 | 0.0713 |
| 245 | 0.0553 | 0.0491 |
| 327 | 0.0362 | 0.0440 |
| 409 | 0.0282 | 0.0352 |
| 491 | 0.0282 | 0.0412 |
| 573 | 0.0256 | 0.0293 |
| 655 | 0.0238 | 0.0252 |
| 737 | 0.0175 | 0.0226 |
| 819 | 0.0154 | 0.0228 |
| 901 | 0.0116 | 0.0205 |
| 983 | 0.0160 | 0.0202 |
| 1065 | 0.0146 | 0.0240 |
| 1147 | 0.0182 | 0.0180 |
| 1229 | 0.0171 | 0.0192 |
| 1311 | 0.0091 | 0.0174 |
| 1393 | 0.0171 | 0.0158 |
| 1475 | 0.0137 | 0.0158 |
| 1557 | 0.0158 | 0.0148 |
| 1639 | 0.0165 | 0.0149 |