Spaces:
Running
Running
Update app.py
Browse filesChange number of labels
app.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import numpy as np
|
4 |
-
from transformers import (AutoTokenizer, AutoModelForSequenceClassification)
|
5 |
-
|
6 |
-
model = AutoModelForSequenceClassification.from_pretrained('tiedaar/metacognitive-cls',
|
7 |
-
num_labels=
|
8 |
-
problem_type = "multi_label_classification")
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained('tiedaar/metacognitive-cls', use_fast=False)
|
10 |
-
|
11 |
-
labels = list(model.config.id2label.values())
|
12 |
-
|
13 |
-
def sigmoid(x):
|
14 |
-
return 1/(1 + np.exp(-x))
|
15 |
-
|
16 |
-
def generate_output(sequence):
|
17 |
-
input_ids = tokenizer(sequence, return_tensors='pt')['input_ids']
|
18 |
-
outputs = np.array(model(input_ids).logits.detach().reshape(-1))
|
19 |
-
predictions = sigmoid(outputs)
|
20 |
-
predictions = (predictions > 0.5).astype(int)
|
21 |
-
return predictions
|
22 |
-
|
23 |
-
st.title("Metacognitive Strategy Classification")
|
24 |
-
st.subheader("This app classifies natural language descriptions of study strategies according to the metacognitive strategies being employed")
|
25 |
-
|
26 |
-
sequence = st.text_area("Please input the text here")
|
27 |
-
df = pd.DataFrame(columns=labels)
|
28 |
-
if st.button("Click here"):
|
29 |
-
resp = generate_output(sequence)
|
30 |
-
df.loc[len(df)] = resp
|
31 |
st.table(df)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from transformers import (AutoTokenizer, AutoModelForSequenceClassification)
|
5 |
+
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained('tiedaar/metacognitive-cls',
|
7 |
+
num_labels=10,
|
8 |
+
problem_type = "multi_label_classification")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained('tiedaar/metacognitive-cls', use_fast=False)
|
10 |
+
|
11 |
+
labels = list(model.config.id2label.values())
|
12 |
+
|
13 |
+
def sigmoid(x):
|
14 |
+
return 1/(1 + np.exp(-x))
|
15 |
+
|
16 |
+
def generate_output(sequence):
|
17 |
+
input_ids = tokenizer(sequence, return_tensors='pt')['input_ids']
|
18 |
+
outputs = np.array(model(input_ids).logits.detach().reshape(-1))
|
19 |
+
predictions = sigmoid(outputs)
|
20 |
+
predictions = (predictions > 0.5).astype(int)
|
21 |
+
return predictions
|
22 |
+
|
23 |
+
st.title("Metacognitive Strategy Classification")
|
24 |
+
st.subheader("This app classifies natural language descriptions of study strategies according to the metacognitive strategies being employed")
|
25 |
+
|
26 |
+
sequence = st.text_area("Please input the text here")
|
27 |
+
df = pd.DataFrame(columns=labels)
|
28 |
+
if st.button("Click here"):
|
29 |
+
resp = generate_output(sequence)
|
30 |
+
df.loc[len(df)] = resp
|
31 |
st.table(df)
|