Downloads · 30 days
0
AiresPucrs/BiLSTM-sentiment-classifier-adversarial
BiLSTM-sentiment-classifier-adversarial is a machine learning model from AiresPucrs. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This model is part of a tutorial tied to the Teeny-Tiny Castle, an open-source repository containing educational tools for AI Ethics and Safety research.
Downloads · 30 days
0
Access
Public
Updated Oct 13, 2024
Repo size
28.9 MB
Likes
0
Public
Click a slice to open those files.
.json18.7 MB · 65%
From the Hugging Face model README
This model is part of a tutorial tied to the Teeny-Tiny Castle, an open-source repository containing educational tools for AI Ethics and Safety research.
import json
import torch
import numpy as np
import pandas as pd
import tensorflow as tf
from huggingface_hub import hf_hub_download
# Download the model
hf_hub_download(repo_id="AiresPucrs/BiLSTM-sentiment-classifier-adversarial",
filename="BiLSTM-sentiment-classifier-adversarial.h5",
local_dir="./",
repo_type="model"
)
# Download the tokenizer file
hf_hub_download(repo_id="AiresPucrs/BiLSTM-sentiment-classifier-adversarial",
filename="tokenizer-BiLSTM-sentiment-classifier-adversarial.json",
local_dir="./",
repo_type="model"
)
model = tf.keras.models.load_model('./BiLSTM-sentiment-classifier.h5')
with open('./tokenizer-BiLSTM-sentiment-classifier.json') as fp:
data = json.load(fp)
tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(data)
fp.close()
strings = [
'this explanation is really bad',
'i did not like this tutorial 2/10',
'this tutorial is garbage i wont my money back',
'is nice to see philosophers doing machine learning',
'this is a great and wonderful example of nlp',
'this tutorial is great one of the best tutorials ever made'
]
preds = model.predict(
tf.keras.preprocessing.sequence.pad_sequences(
tokenizer.texts_to_sequences(strings),
maxlen=250,
truncating='post'
), verbose=0)
for i, string in enumerate(strings):
print(f'Review: "{string}"\n(Negative 😊 {preds[i][0] * 100:.2f}% | Positive 😔 {preds[i][1] * 100:.2f}%)\n')