Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

vivekpadia70 vivekpadia70

🏠
Working from home
View GitHub Profile
View aws_sentiment.py
body = {"query":{"bool":{"must":[{"match_all":{}}],"filter":[{"range":{"SentimentScore.Positive":{"gt": positiveSentiment}}}]}}, "sort":{"SentimentScore.Positive": {"order":"desc"}}}
result = es.search(index="quotes", body=body)
View sentiment.json
{
"sr": "Složen sistem koji radi je bez izuzetka evoluirao od jednostavnog sistema koja je radio. Obrnuta tvrdnja takođe izgleda istinita: složen sistem projektovan od nule nikad ne radi i ne može biti napravljen da radi.",
"en": "A complex system that works is invariably found to have evolved from a simple system that worked. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work.",
"author": "John Gall (author)",
"source": "",
"numberOfVotes": 2,
"rating": 3.2,
"addedBy": "5ab04d928c8b4e3cbf733557",
"id": "5a6ce8702af929789500e887",
"SentimentScore": {
View sentiment.json
"Sentiment": "NEUTRAL",
"SentimentScore": {
"Mixed": 0.0040211002342402935,
"Negative": 0.3506680130958557,
"Neutral": 0.6395053863525391,
"Positive": 0.005805556662380695
}
View aws_sentiment.py
host = '' # For example, my-test-domain.us-east-1.es.amazonaws.com
region = '' # e.g. us-west-1
service = 'es'
awsauth = AWS4Auth(settings.AWS_ACCESS_KEY, settings.AWS_SECRET_KEY, region, service)
es = Elasticsearch(
hosts = [{'host': host, 'port': 443}],
http_auth = awsauth,
use_ssl = True,
View aws_sentiment.py
comprehend = boto3.client(service_name='comprehend', region_name='region', aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY,)
sentiment = json.dumps(comprehend.detect_sentiment(Text=text, LanguageCode='en'), sort_keys=True, indent=4)
View imdb_lstm.py
history = model.fit(padded_train, train_label, epochs=4, validation_data=(padded_test, test_label))
View imdb_lstm.py
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
View imdb_lstm.py
model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(13000, 16, input_length=max_len_text))
model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64, dropout=0.2)))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
model.summary()
View imdb_lstm.py
padded_train = pad_sequences(train_data, maxlen=max_len_text)
padded_test = pad_sequences(test_data, maxlen=max_len_text)
View imdb_lstm.py
train_data = np.array(vector)[:train_set]
train_label = (np.array(df['sentiment'])[:train_set])
test_data = np.array(vector)[train_set:]
test_label = (np.array(df['sentiment'])[train_set:])
You can’t perform that action at this time.