L
L
LakeForest2021-08-12 14:01:36
Python
LakeForest, 2021-08-12 14:01:36

How to rewrite the string torch.argmax(model_out[0], dim=-1) without using torch?

I don't want to load the library for the sake of two lines...

model = transformers.AutoModelForTokenClassification.from_pretrained('model').to(device)
...
 with torch.no_grad():
        model_out = model(**encoded)
 predicted_tokens = torch.argmax(model_out[0], dim=-1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imageman, 2021-08-12
@imageman

I do not want to load the torch library - how is it? Are you using it to the fullest? Through what do you calculate the values ​​of the model? After all, the line "with torch.no_grad()" is there for a reason.
Why did you decide to save on matches? Running time, saving memory?
Try instead of the "problematic" "torch.argmax(model_out[0], dim=-1)" to put 0 and analyze how resource usage has changed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question