--- license: apache-2.0 language: - en --- # BiLSTM Sentiment Classifier Adversarial (Teeny-Tiny Castle) This model is part of a tutorial tied to the [Teeny-Tiny Castle](https://github.com/Nkluge-correa/TeenyTinyCastle), an open-source repository containing educational tools for AI Ethics and Safety research. ## How to Use ```python 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') ```