Add implementation for built-in jaccard similarity#70
Add implementation for built-in jaccard similarity#70jstammers wants to merge 6 commits intoNickCrews:mainfrom
Conversation
|
I think this is worth considering, but watch out:
I think the fact that you and the writers of duckdb had two different assumptions here shows that being implicit here can lead to mistakes. I could see users of mismo wanting either method in different situations. One option is to just not support it, and make users call What about an API of something like from typing import Literal
def jaccard(a: ir.StringValue, b: ir.StringValue, *, tokenize: Literal["by_character", "on_whitespace"]) -> ir.FloatingValue:
....Then the user has to explicitly choose the method they want. Make it required, so no hidden default. kwarg so it is clear. I would love to workshop the names. Is there some other common method we're missing here? Of course, the user can just implement it themselves with |
| [ | ||
| ("foo", "foo", 1), | ||
| ("foo bar", "foo", 0.3333), # this is currently failing | ||
| ("foo bar", "bar foo", 1), |
There was a problem hiding this comment.
Let's figure out the semantics first in the main comment thread, but eventually I will want to see
- empty case
- NULL case
- case with repeated elements in one set, eg jaccard("foo foo bar", "foo baz") -> 1/3
|
Thanks for spotting that @NickCrews. I hadn't considered the fact that duckdb considers each character as a separate element. From a quick search online, I've found multiple examples for both tokenizing by word and by character, so I think it makes sense to be explicit about which method to use when calculating the jaccard similarity of two strings of text. |
|
I've added some functionality to tokenize either by word or by character (perhaps something like |
Adds the duckdb builtin jaccard similarity which currently does not always result in the same value as
mismo.sets.jaccard