Different results on hugging face and by using code

#1
by thaheem422 - opened

Hi, I am having an issue with the results. I am getting different results on hugging face website and by using code on my computer. The results on hugging face are correct but I get incorrect results on my computer. for example I get "learning and educational" on hugging face and "business and entrepreneurship" on my computer for "The best way to predict the future is to create it.
@ferozekhaan."

Hello, I tried the example you provided on Google's colab and I am getting "learning and educational" as on hugging face. I am not really sure why are you getting different results to be honest. Maybe try setting the model to evaluation by using model.eval() before making the predictions. Can you provide some more info about your setup.

image.png

# Torch
model = AutoModelForSequenceClassification.from_pretrained('cardiffnlp/tweet-topic-21-multi')
tokenizer = AutoTokenizer.from_pretrained('cardiffnlp/tweet-topic-21-multi')

class_mapping = model.config.id2label


tokens = tokenizer(text, return_tensors='pt')
output = model(**tokens)

scores = output[0][0].detach().numpy()
scores = expit(scores)
print(class_mapping[np.argmax(scores)])

>> 'learning_&_educational'

# TF
tf_model = TFAutoModelForSequenceClassification.from_pretrained('cardiffnlp/tweet-topic-21-multi')
tokenizer = AutoTokenizer.from_pretrained('cardiffnlp/tweet-topic-21-multi')

class_mapping = model.config.id2label

# Example text
text = "The best way to predict the future is to create it. @ferozekhaan."
tokens = tokenizer(text, return_tensors='tf')
output = tf_model(**tokens)
scores = output[0][0]

print(class_mapping[np.argmax(scores)])
>> learning_&_educational

Sign up or log in to comment