huggingface / huggingface/sentence-transformers

Expected object of scalar type Bool but got scalar type Byte for argument #2

Open Beginner friendly
#173 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
19.1k
Forks
2.9k
Avg merge
1d 19h
Merged PRs (30d)
61

Description

im trying to use BatchHardTripletLoss you provided as Loss function in combination with SentenceLabelDataset (it works without any issue when i use the normal TripletLoss)

when i start the fit method, i get the error:

`RuntimeError: Expected object of scalar type Bool but got scalar type Byte for argument #2 'other' in call to _th_and`

it occurs at _get_anchor_positive_triplet_mask method, and the whole dump is like:

```
raceback (most recent call last): | 0/152 [00:00
cli.main()
File "c:\Users\tyker1\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 427, in main
run()
File "c:\Users\tyker1\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 264, in run_file
runpy.run_path(options.target, run_name="__main__")
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\MeinProgramme\MeinPython\Masterarbeit\pythonCodes\siameseTest\sbert-test.py", line 56, in
fp16_opt_level='O2')
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\sentence_transformers\SentenceTransformer.py", line 351, in fit
loss_value = loss_model(features, labels)
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\apex\amp\_initialize.py", line 197, in new_fwd
**applier(kwargs, input_caster))
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\sentence_transformers\losses\BatchHardTripletLoss.py", line 15, in forward
return BatchHardTripletLoss.batch_hard_triplet_loss(labels, reps[0], margin=self.triplet_margin)
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\sentence_transformers\losses\BatchHardTripletLoss.py", line 39, in batch_hard_triplet_loss
mask_anchor_positive = BatchHardTripletLoss._get_anchor_positive_triplet_mask(labels).float()
File "C:\Users\tyker1\AppData\Local\Programs\Python\Python37\lib\site-packages\sentence_transformers\losses\BatchHardTripletLoss.py", line 188, in _get_anchor_positive_triplet_mask
return labels_equal & indices_not_equal
RuntimeError: Expected object of scalar type Bool but got scalar type Byte for argument #2 'other' in call to _th_and
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in sentence_transformers/losses/BatchHardTripletLoss.py, especially _get_anchor_positive_triplet_mask and the batch_hard_triplet_loss call shown in the traceback. Reproduce the failure with BatchHardTripletLoss and SentenceLabelDataset during fit; done when this combination runs without the Bool/Byte runtime error while normal TripletLoss behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.