--- license: apache-2.0 library_name: keras --- # BiLSTM Sentiment Classifier (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 from huggingface_hub import hf_hub_download # Download the model hf_hub_download(repo_id="AiresPucrs/BiLSTM-sentiment-classifier",                 filename="BiLSTM-sentiment-classifier.h5",                 local_dir="./",                 repo_type="model" ) # Download the tokenizer file hf_hub_download(repo_id="AiresPucrs/BiLSTM-sentiment-classifier",                 filename="tokenizer-BiLSTM-sentiment-classifier.json",                 local_dir="./",                 repo_type="model" ) import json import torch import numpy as np import pandas as pd import tensorflow as tf 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 😊 {round((preds[i][0]) * 100)}% | Positive 😔 {round(preds[i][1] * 100)}%)\n') ```