Make sentiment predictions blocking
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -20,7 +20,7 @@ use time::OffsetDateTime;
|
||||
use tokio::{
|
||||
join, spawn,
|
||||
sync::{mpsc, oneshot, Mutex, RwLock},
|
||||
task::JoinHandle,
|
||||
task::{block_in_place, JoinHandle},
|
||||
time::sleep,
|
||||
};
|
||||
|
||||
@@ -397,13 +397,14 @@ async fn execute_backfill_news(
|
||||
let predictions = join_all(inputs.chunks(app_config.max_bert_inputs).map(|inputs| {
|
||||
let sequence_classifier = app_config.sequence_classifier.clone();
|
||||
async move {
|
||||
sequence_classifier
|
||||
.lock()
|
||||
.await
|
||||
.predict(inputs.iter().map(String::as_str).collect::<Vec<_>>())
|
||||
.into_iter()
|
||||
.map(|label| Prediction::try_from(label).unwrap())
|
||||
.collect::<Vec<_>>()
|
||||
let sequence_classifier = sequence_classifier.lock().await;
|
||||
block_in_place(|| {
|
||||
sequence_classifier
|
||||
.predict(inputs.iter().map(String::as_str).collect::<Vec<_>>())
|
||||
.into_iter()
|
||||
.map(|label| Prediction::try_from(label).unwrap())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
}
|
||||
}))
|
||||
.await
|
||||
|
Reference in New Issue
Block a user