Skip to content

Commit

Permalink
added folder google-colab
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoperea20 authored May 26, 2023
1 parent 6e0e4f9 commit 2b2b42c
Show file tree
Hide file tree
Showing 6 changed files with 1,153 additions and 0 deletions.
291 changes: 291 additions & 0 deletions Google-colab-methods/met4_evitoverf (1).ipynb

Large diffs are not rendered by default.

211 changes: 211 additions & 0 deletions Google-colab-methods/metodo1_pading.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Google-colab-methods/metodo2.ipynb

Large diffs are not rendered by default.

293 changes: 293 additions & 0 deletions Google-colab-methods/metodo3.ipynb

Large diffs are not rendered by default.

282 changes: 282 additions & 0 deletions Google-colab-methods/metodo4.ipynb

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions Google-colab-methods/metodo_4_aprueba.ipynb
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.\")"
]
}
]
}

0 comments on commit 2b2b42c

Please sign in to comment.