BiLSTM Sentiment Classifier Adversarial (Teeny-Tiny Castle)
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.
How to Use
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')
Inference Providers
NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API:
The model has no library tag.