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
body = {"query":{"bool":{"must":[{"match_all":{}}],"filter":[{"range":{"SentimentScore.Positive":{"gt": positiveSentiment}}}]}}, "sort":{"SentimentScore.Positive": {"order":"desc"}}} | |
result = es.search(index="quotes", body=body) |
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
{ | |
"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": { |
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
"Sentiment": "NEUTRAL", | |
"SentimentScore": { | |
"Mixed": 0.0040211002342402935, | |
"Negative": 0.3506680130958557, | |
"Neutral": 0.6395053863525391, | |
"Positive": 0.005805556662380695 | |
} |
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
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, |
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
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) |
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
history = model.fit(padded_train, train_label, epochs=4, validation_data=(padded_test, test_label)) |
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
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) |
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
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() |
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
padded_train = pad_sequences(train_data, maxlen=max_len_text) | |
padded_test = pad_sequences(test_data, maxlen=max_len_text) |
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
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:]) |
NewerOlder