mirror of
https://github.com/Steffo99/unimore-bda-6.git
synced 2024-11-21 23:44:19 +00:00
Some memory usage tweaks
This commit is contained in:
parent
35616d35c7
commit
61141248db
3 changed files with 69 additions and 64 deletions
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -12,7 +12,6 @@
|
|||
"justMyCode": false,
|
||||
"env": {
|
||||
"NLTK_DATA": "./data/nltk",
|
||||
"DATA_SET_SIZE": "250",
|
||||
"XLA_FLAGS": "--xla_gpu_cuda_data_dir=/opt/cuda"
|
||||
},
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
|
|
@ -31,8 +31,6 @@ def main():
|
|||
log.fatal("MongoDB database is not available, exiting...")
|
||||
exit(1)
|
||||
|
||||
reviews = reviews_collection(db)
|
||||
|
||||
for sample_func in [
|
||||
sample_reviews_polar,
|
||||
sample_reviews_varied,
|
||||
|
@ -94,7 +92,13 @@ def main():
|
|||
slog.warning("%s is not supported by %s, skipping run...", SentimentAnalyzer.__name__, Tokenizer.__name__)
|
||||
break
|
||||
|
||||
with Caches.from_database_samples(collection=reviews, sample_func=sample_func) as datasets:
|
||||
|
||||
with mongo_client_from_config() as db:
|
||||
reviews = reviews_collection(db)
|
||||
datasets_cm = Caches.from_database_samples(collection=reviews, sample_func=sample_func)
|
||||
datasets = datasets_cm.__enter__()
|
||||
|
||||
try:
|
||||
try:
|
||||
slog.info("Training sentiment analyzer: %s", sa)
|
||||
sa.train(training_dataset_func=datasets.training, validation_dataset_func=datasets.validation)
|
||||
|
@ -111,6 +115,8 @@ def main():
|
|||
successful_runs += 1
|
||||
cumulative_evaluation_results += evaluation_results
|
||||
break
|
||||
finally:
|
||||
datasets_cm.__exit__()
|
||||
|
||||
slog.info("Cumulative evaluation results: %s", cumulative_evaluation_results)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ def mongo_client_from_config() -> t.ContextManager[pymongo.MongoClient]:
|
|||
|
||||
yield client
|
||||
|
||||
log.info("Closing connection to MongoDB...")
|
||||
log.debug("Closing connection to MongoDB...")
|
||||
client.close()
|
||||
log.debug("Closed connection to MongoDB!")
|
||||
|
||||
|
|
Loading…
Reference in a new issue