Comments (6)
It should still be two [N, d] tensors meaning N tensors each with dimension d.
First the function should calculate the cosine similarity between the two tensors and then it should have a reduction
argument that determines if we should take the sum
or the mean
over the batch dimension
from torchmetrics.
Hi,
https://pytorch.org/docs/stable/generated/torch.nn.CosineSimilarity.html. There is already cosine similarity in torch. Can I use it?
from torchmetrics.
@avinashsai depends on your purpose.
If you want the calculate the mean score on a single batch, no problem.
But lets say that you want to accumulate over a complete dataset, then you need some kind of custom accumulation:
preds = [torch.randn(5, 2), torch.randn(10, 2)]
target = [torch.randn(5, 2), torch.randn(10, 2)]
individual_scores = []
for p,t in zip(preds, target):
individual_scores.append(torch.nn.CosineSimilarity()(p, t).mean())
# total score and correct score is different
total_score = torch.mean(torch.stack(individual_scores))
correct_score = torch.nn.CosineSimilarity()(torch.cat(preds, dim=0), torch.cat(target, dim=0)).mean()
the global mean does not equal the mean of the score on the individual batches.
This is basically the reason why we also have custom implementation of mean squared error, mean absolute error ect even though these are also a part of pytorch, because when you want to accumulate over multiple batches you need to be careful about the order of operations.
from torchmetrics.
@SkafteNicki Thanks for the clarification. So, this cosine similarity metric will compute between 2 n-dim tensors??
from torchmetrics.
Hey, I would like to work on this, could you assign it to me?
from torchmetrics.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from torchmetrics.
Related Issues (20)
- Discrepancy in optimal threshold calculation between sklearn and torchmetrics ROC implementations HOT 2
- Mean Average Detection ignores `warn_on_many_detections` set to False HOT 1
- `list` states leak (`Tensor`) memory HOT 1
- Behaviors of AUROC and Average Precision are inconsistent when all labels are equal HOT 4
- The default value of `compute_with_cache` should be `True` . HOT 2
- Bug in ERGAS HOT 2
- Ordinal classification metrics HOT 1
- Binary Classification Expected Calibration Error HOT 2
- `intersection_over_union` error HOT 2
- Clarify that nan is supported in zero_division HOT 4
- Add `_filter_kwargs` in `ClasswiseWrapper` metric wrapper HOT 3
- MetricTracker use higher_is_better as default for maximize HOT 2
- Unpredictable class order when `panoptic_quality(..., return_per_class=True)`
- torchmetrics Accuracy HOT 8
- BootStrapper.reset() does not reset properly
- segmentation.MeanIoU is wrong HOT 3
- DataLoader worker is killed in Docker HOT 4
- MeanAveragePrecision - bug in `max_detection_thresholds` HOT 3
- Documentation of ERGAS HOT 1
- Support for DLM (AIM) metric HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchmetrics.