Produces a cos similarity operator Args: a (CTensor): input tensor. b (CTensor): input tensor. Returns: the output Tensor.
(a, b)
| 5003 | |
| 5004 | |
| 5005 | def cossim(a, b): |
| 5006 | """ |
| 5007 | Produces a cos similarity operator |
| 5008 | Args: |
| 5009 | a (CTensor): input tensor. |
| 5010 | b (CTensor): input tensor. |
| 5011 | Returns: |
| 5012 | the output Tensor. |
| 5013 | """ |
| 5014 | assert a.shape == b.shape, "shape not match for cossim" |
| 5015 | assert a.ndim() == 2, "shape should be in 2d for cossim" |
| 5016 | assert b.ndim() == 2, "shape should be in 2d for cossim" |
| 5017 | return CosSim()(a, b)[0] |
| 5018 | |
| 5019 | |
| 5020 | class Expand(Operator): |