Views
No views yet
Predictions on Winter manual dataset
-----
Intra-class Correlation Coefficient:
| Pow (Label_0): | 0.90 |
| Ach (Label_1): | 0.94 |
| Aff (Label_2): | 0.89 |
| mean: | 0.91 |
Pearson correlations:
| Pow (Label_0): 0.800 |
| Ach (Label_1): 0.86 |
| Aff (Label_2): 0.79 |
| mean: 0.82 |
1import json
2import requests
3api_key = "<HF Token>"
4headers = {"Authorization": f"Bearer {api_key}"}
5api_url = "https://utuu5vtk4i2h1vpk.us-east-1.aws.endpoints.huggingface.cloud"
6
7# This is a sentence from the Winter manual that is dual-scored for both Pow and Aff
8prompt = """The recollection of skating on the Charles, and the time she had
9 pushed me through the ice, brought a laugh to the conversation; but
10 it quickly faded in the murky waters of the river that could no
11 longer freeze over."""
12
13# Since this is a multilabel classifier, we want to return scores for the top 3 labels
14data = {"inputs": prompt, "parameters": {"top_k": 3}}
15
16response = requests.request("POST", api_url, headers=headers, json=data)
17
18# Print the labels and scores (arranged in order of likelihood)
19scores = {x['label']: x['score'] for x in response.json()}
20print(scores)
21
22# {'Aff': 0.9999667406082153, 'Pow': 0.999929666519165, 'Ach': 0.0000024892888177}1from transformers import pipeline
2
3# This is the current model, previous models are labeled V2 etc.
4model = "encodingai/electra-base-discriminator-im-multilabel-V3"
5
6# This is a sentence from the Winter manual that is dual-scored for both Pow and Aff
7sentence = """The recollection of skating on the Charles, and the time she had
8 pushed me through the ice, brought a laugh to the conversation; but
9 it quickly faded in the murky waters of the river that could no
10 longer freeze over."""
11
12# Instantiate a text classifier using a standard transformers pipeline
13classifier = pipeline("text-classification", model=model)
14
15# Since this is a multilabel classifier, we want to return scores for the top 3 labels,
16# which we store in a dict for the scored sentence
17scores = {x['label']: x['score'] for x in classifier(sentence, top_k=3)}
18# Print the labels and scores (arranged in order of likelihood)
19print(scores)
20
21# {'Aff': 0.9999632835388184, 'Pow': 0.9999274015426636, 'Ach': 2.489295866325847e-06}
22
23# Or get the rounded scores for each motive
24rounded = {x['label']: int(round(x['score'])) for x in classifier(sentence, top_k=3)}
25print(rounded)
26
27# {'Aff': 1, 'Pow': 1, 'Ach': 0}