This commit is contained in:
AWieczarek 2024-06-11 23:09:14 +02:00
parent 490b8cf773
commit e4a90fd187
6 changed files with 216 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,5 @@
{
"batch_size": 32,
"epochs": 10,
"seed": 541882551
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,100 @@
{
"artifacts": [
"beer_review_sentiment_model.keras"
],
"command": "run_experiment",
"experiment": {
"base_dir": "C:\\Users\\adamw\\REPOS\\ium_464979\\sacred",
"dependencies": [
"keras==2.12.0",
"numpy==1.23.5",
"sacred==0.8.5",
"scikit-learn==1.2.2"
],
"mainfile": "sacred_training_model.py",
"name": "464979",
"repositories": [
{
"commit": "490b8cf77306ea482543e03ba29e37b07f689ae1",
"dirty": true,
"url": "https://git.wmi.amu.edu.pl/s464979/ium_464979.git"
}
],
"sources": [
[
"sacred_training_model.py",
"_sources\\sacred_training_model_ccb7ce6317e0e291ec9a10a9f4fffffe.py"
]
]
},
"heartbeat": "2024-06-11T21:08:46.548013",
"host": {
"ENV": {},
"cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
"gpus": {
"driver_version": "555.85",
"gpus": [
{
"model": "NVIDIA GeForce GTX 1660 Ti",
"persistence_mode": false,
"total_memory": 6144
}
]
},
"hostname": "DESKTOP-9SEHQM2",
"os": [
"Windows",
"Windows-10-10.0.19045-SP0"
],
"python_version": "3.11.7"
},
"meta": {
"command": "run_experiment",
"config_updates": {},
"named_configs": [],
"options": {
"--beat-interval": null,
"--capture": null,
"--comment": null,
"--debug": false,
"--enforce_clean": false,
"--file_storage": null,
"--force": false,
"--help": false,
"--id": null,
"--loglevel": null,
"--mongo_db": null,
"--name": null,
"--pdb": false,
"--print-config": false,
"--priority": null,
"--queue": false,
"--s3": null,
"--sql": null,
"--tiny_db": null,
"--unobserved": false,
"COMMAND": null,
"UPDATE": [],
"help": false,
"with": false
}
},
"resources": [
[
"C:\\Users\\adamw\\REPOS\\ium_464979\\sacred\\beer_reviews_train.csv",
"sacred_runs\\_resources\\beer_reviews_train_e8dab75a0ec202f56510a0e1f9926ad7.csv"
],
[
"C:\\Users\\adamw\\REPOS\\ium_464979\\sacred\\beer_reviews_test.csv",
"sacred_runs\\_resources\\beer_reviews_test_56070f83bef3ee1d17d1a632aa55b798.csv"
]
],
"result": {
"dtype": "float64",
"py/object": "numpy.float64",
"value": 0.9237146778770103
},
"start_time": "2024-06-11T21:08:35.823687",
"status": "COMPLETED",
"stop_time": "2024-06-11T21:08:46.547012"
}

View File

@ -0,0 +1,84 @@
import pandas as pd
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, GlobalAveragePooling1D, Dense
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, mean_squared_error
from sacred import Experiment
from sacred.observers import MongoObserver, FileStorageObserver
from math import sqrt
ex = Experiment('464979')
# ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@tzietkiewicz.vm.wmi.amu.edu.pl:27017'))
ex.observers.append(FileStorageObserver('sacred_runs'))
@ex.config
def my_config():
epochs = 10
batch_size = 32
@ex.automain
def run_experiment(epochs, batch_size, _run):
train_data = pd.read_csv('beer_reviews_train.csv')
X_train = train_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
y_train = train_data['review_overall']
tokenizer = Tokenizer(num_words=10000)
tokenizer.fit_on_texts(X_train)
X_train_seq = tokenizer.texts_to_sequences(X_train)
X_train_pad = pad_sequences(X_train_seq, maxlen=100)
model = Sequential([
Embedding(input_dim=10000, output_dim=16, input_length=100),
GlobalAveragePooling1D(),
Dense(16, activation='relu'),
Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
model.fit(X_train_pad, y_train, epochs=epochs, batch_size=batch_size, validation_split=0.1)
model.save('beer_review_sentiment_model.keras')
_run.add_artifact('beer_review_sentiment_model.keras')
test_data = pd.read_csv('beer_reviews_test.csv')
X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
y_test = test_data['review_overall']
tokenizer = Tokenizer(num_words=10000)
tokenizer.fit_on_texts(X_test)
X_test_text = X_test.astype(str).agg(' '.join, axis=1)
X_test_seq = tokenizer.texts_to_sequences(X_test_text)
X_test_pad = pad_sequences(X_test_seq, maxlen=100)
predictions = model.predict(X_test_pad)
if len(predictions.shape) > 1:
predictions = predictions[:, 0]
results = pd.DataFrame({'Predictions': predictions, 'Actual': y_test})
results.to_csv('beer_review_sentiment_predictions.csv', index=False)
y_pred = results['Predictions']
y_test = results['Actual']
y_test_binary = (y_test >= 3).astype(int)
accuracy = accuracy_score(y_test_binary, y_pred.round())
precision, recall, f1, _ = precision_recall_fscore_support(y_test_binary, y_pred.round(), average='micro')
rmse = sqrt(mean_squared_error(y_test, y_pred))
print(f'Accuracy: {accuracy}')
print(f'Micro-avg Precision: {precision}')
print(f'Micro-avg Recall: {recall}')
print(f'F1 Score: {f1}')
print(f'RMSE: {rmse}')
_run.add_resource('./beer_reviews_train.csv')
_run.add_resource('./beer_reviews_test.csv')
return accuracy