Code Monkey home page Code Monkey logo

ktuner's Introduction

elmazzun

Hi everybody!
This is elmazzun, Linux enthusiast.

⚠️ ⚠️ ⚠️

For your own safety, do NOT clone any of my repositories as they are just a huge personal learning space where I study different topics.

⚠️ ⚠️ ⚠️

Some stats about me

GitHub Streak

Top Langs

Trophies

I like to...

  • ...automate stuff with

    because I hate repetitive tasks

  • ...isolate my work with

    for a clean working environment

  • ...explore

    because that's where the magic happens

ktuner's People

Watchers

 avatar

ktuner's Issues

rnn sentiment analysis

# -*- coding: utf-8 -*-
"""
Created on Sun Jan  8 17:22:19 2023

@author: gostl
"""

import numpy as np
import pandas as pd

from keras.models import Sequential
from keras.layers import Dense, LSTM, Embedding, Bidirectional, GlobalAveragePooling1D, Dropout
from keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import tensorflow as tf
import keras.utils as ku

data=pd.read_csv(r"C:\Users\gostl\OneDrive\Desktop\data\movie_reviews.csv")[:10000]

y=data["sentiment"]
y = np.array(list(map(lambda x: 1 if x=="positive" else 0, y))).astype("float32")
x_train,x_test,y_train,y_test=train_test_split(data["review"],y,test_size=0.3)

t=Tokenizer()
t.fit_on_texts(x_train)
x_train=t.texts_to_sequences(x_train)
x_test=t.texts_to_sequences(x_test)
voc_size=len(t.word_index)

max_words=300
x_train=pad_sequences(x_train, maxlen=max_words)
x_test=pad_sequences(x_test, maxlen=max_words)

batch_size=30
x_train2,y_train2=x_train[batch_size:],y_train[batch_size:]
x_val,y_val=x_train[:batch_size],y_train[:batch_size]

model=Sequential()
model.add(Embedding(voc_size+1, 512, input_length=max_words))
model.add(LSTM(100))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss="binary_crossentropy", metrics="accuracy")
model.fit(x_train2,y_train2, validation_data=(x_val,y_val),batch_size=batch_size, epochs=5)
y_pred=model.predict(x_test)
y_score=[1 if i>0.5 else 0 for i in y_pred]
score=model.evaluate(x_test,y_test)
print(score)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.