File size: 1,289 Bytes
7af72c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
import pandas as pd
import numpy as np
from transformers import (AutoTokenizer, AutoModelForSequenceClassification)

model = AutoModelForSequenceClassification.from_pretrained('tiedaar/metacognitive-cls',
                                                           num_labels=8,
                                                           problem_type = "multi_label_classification")
tokenizer = AutoTokenizer.from_pretrained('tiedaar/metacognitive-cls', use_fast=False)

labels = list(model.config.id2label.values())

def sigmoid(x):
   return 1/(1 + np.exp(-x))
    
def generate_output(sequence):
    input_ids = tokenizer(sequence, return_tensors='pt')['input_ids']
    outputs = np.array(model(input_ids).logits.detach().reshape(-1))
    predictions = sigmoid(outputs)
    predictions = (predictions > 0.5).astype(int)
    return predictions

st.title("Metacognitive Strategy Classification")
st.subheader("This app classifies natural language descriptions of study strategies according to the metacognitive strategies being employed")

sequence = st.text_area("Please input the text here")
df = pd.DataFrame(columns=labels)
if st.button("Click here"):
    resp = generate_output(sequence)
    df.loc[len(df)] = resp
    st.table(df)