{ "cells": [ { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "\n", "import tensorflow as tf\n", "import opendatasets as od\n", "import numpy as np\n", "from tensorflow.keras import layers\n", "from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline\n", "\n", "tf.get_logger().setLevel('ERROR')\n", "tokenizer = AutoTokenizer.from_pretrained(\"blanchefort/rubert-base-cased-sentiment-rurewiews\")" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "model = AutoModelForSequenceClassification.from_pretrained(\"blanchefort/rubert-base-cased-sentiment-rurewiews\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "pipe = pipeline(\"text-classification\", model=\"blanchefort/rubert-base-cased-sentiment-rurewiews\")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'label': 'NEUTRAL', 'score': 0.5040543079376221}]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pipe(\"Product is ok ok sounds also good but I am not feeling like 525 watts and weight also very less 525 watts means atleast 8kg or 10kg will be there and in paper they mentioned 5 modes are different on speaker what they given modes are different totally confused with this product\")" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Skipping, found downloaded files in \"restaurent_review\\reviews\" (use force=True to force download)\n" ] } ], "source": [ "import gradio as gr\n", "import pandas as pd\n", "import opendatasets as od\n", "\n", "od.download_kaggle_dataset('vigneshwarsofficial/reviews', data_dir='restaurent_review')\n", "prediction_data = pd.read_csv('restaurent_review/reviews/Restaurant_Reviews.tsv', delimiter='\\t')\n", "\n", "prediction_data.pop(\"Liked\")\n", "\n", "data = list(prediction_data[\"Review\"])\n", "results = pipe(data)\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Wow... Loved this place.',\n", " 'Crust is not good.',\n", " 'Not tasty and the texture was just nasty.',\n", " 'Stopped by during the late May bank holiday off Rick Steve recommendation and loved it.',\n", " 'The selection on the menu was great and so were the prices.']" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[:5]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | count | \n", "sentiment | \n", "
---|---|---|
0 | \n", "283 | \n", "Positive | \n", "
1 | \n", "419 | \n", "Negative | \n", "
2 | \n", "298 | \n", "Neutral | \n", "