Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove batch encoder #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions asreviewcontrib/semantic_clustering/semantic_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ def run_clustering_steps(

# tokenize abstracts and add to data
print("Tokenizing abstracts...")
encoded = tokenizer.batch_encode_plus(
data['abstract'].tolist(),
add_special_tokens=False,
truncation=True,
max_length=200,
padding='max_length',
return_tensors='pt')
encoded = data['abstract'].progress_apply(
lambda x: tokenizer.encode_plus(
x,
add_special_tokens=False,
truncation=True,
max_length=512,
# padding='max_length',
return_tensors='pt'))

# generate embeddings and format correctly
print("Generating embeddings...")
embeddings = []
for x in tqdm(encoded.input_ids):
embeddings.append(model(x.unsqueeze(0), output_hidden_states=False)[-1].detach().numpy().squeeze()) # noqa: E501
for x in tqdm(encoded):
embeddings.append(model(**x, output_hidden_states=False)[-1].detach().numpy().squeeze()) # noqa: E501
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the noqa.


# from here on the data is not directly attached to the dataframe anymore,
# as a result of legacy code. This will be fixed in a future PR.
Expand Down