Spaces:
Sleeping
Sleeping
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) |