-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e0e4f9
commit 2b2b42c
Showing
6 changed files
with
1,153 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "czzTKWpsdadd", | ||
"outputId": "cfa697a8-e18c-4914-a0d3-19e8af0d6929" | ||
}, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Enter a review for classification: nice video\n", | ||
"1/1 [==============================] - 0s 58ms/step\n", | ||
"Prediction: 0.6315826177597046\n", | ||
"Positive review!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from tensorflow.keras.models import load_model\n", | ||
"from tensorflow.keras.datasets import imdb\n", | ||
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"# Cargar el modelo guardado\n", | ||
"model = load_model('modelo.h5')\n", | ||
"\n", | ||
"# Prompt the user to enter a review for classification\n", | ||
"user_review = input(\"Enter a review for classification: \")\n", | ||
"# the movie was very stupid and bad the worsdt movie in al times :negative\n", | ||
"# nice video : positive\n", | ||
"\n", | ||
"# Tokenize the user's review using the IMDB dataset's word index\n", | ||
"word_index = imdb.get_word_index()\n", | ||
"user_tokens = [word_index[word] if word in word_index else 0 for word in user_review.split()]\n", | ||
"\n", | ||
"# Pad the user's tokens to a maximum length of 256 words\n", | ||
"maxlen = 256\n", | ||
"user_padded = pad_sequences([user_tokens], maxlen=maxlen)\n", | ||
"\n", | ||
"# Use the trained model to predict the sentiment of the user's review\n", | ||
"prediction = model.predict(user_padded)[0][0]\n", | ||
"\n", | ||
"# Print the predicted sentiment\n", | ||
"if prediction >= 0.5:\n", | ||
" print(f\"Prediction: {prediction}\")\n", | ||
" print(\"Positive review!\")\n", | ||
"else:\n", | ||
" print(f\"Prediction: {prediction}\")\n", | ||
" print(\"Negative review.\")" | ||
] | ||
} | ||
] | ||
} |