Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the [demo notebook](demo.ipynb) for a more interactive example.
```
from tako_query_filter.filter import TakoQueryFilter

query_filter = TakoQueryFilter.load_with_keywords()
query_filter = TakoQueryFilter()

queries = [
"aapl vs nvda",
Expand Down
11 changes: 2 additions & 9 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from tako_query_filter.filter import TakoQueryFilter\n",
"\n",
"query_filter = TakoQueryFilter.load_with_keywords()\n"
"query_filter = TakoQueryFilter()"
]
},
{
Expand Down Expand Up @@ -48,13 +48,6 @@
"for query, pred in zip(queries, preds):\n",
" print(f\"{query} -> {pred}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include = ["keywords.json"]
name = "tako-query-filter"
packages = [{include = "tako_query_filter", from = "src"}]
readme = "README.md"
version = "0.1.4"
version = "0.2.0"

[tool.poetry.dependencies]
en-tako-query-filter = {url = "https://huggingface.co/TakoData/en_tako_query_filter/resolve/main/en_tako_query_filter-any-py3-none-any.whl"}
Expand Down
21 changes: 7 additions & 14 deletions src/tako_query_filter/filter.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import json
import re
from typing import List, Optional, Set
from typing import Iterable, List
import spacy
import hashlib
from importlib import resources
from tako_query_filter.keywords import keywords


class TakoQueryFilter:
def __init__(
self,
keyword_hashes: Set[str],
keyword_hashes: Iterable[str] = keywords,
):
self.nlp = spacy.load("en_tako_query_filter")
self.keywords_hashes = keyword_hashes
self.keywords_hashes = set(keyword_hashes)
self.keyword_match_score = 0.9

@classmethod
def load_with_keywords(
cls,
keywords_path: Optional[str] = None,
keywords_path: str,
):
"""Load TakoQueryFilter with a set of whitelist keywords.

Expand All @@ -28,15 +28,8 @@ def load_with_keywords(
Returns:
TakoQueryFilter: Initialized filter with models loaded from local paths
"""

if not keywords_path:
with resources.files("tako_query_filter").joinpath("keywords.json").open(
"r"
) as f:
keyword_hashes = set(json.load(f))
else:
with open(keywords_path, "r") as f:
keyword_hashes = set(json.load(f))
with open(keywords_path, "r") as f:
keyword_hashes = json.load(f)

return cls(keyword_hashes)

Expand Down
2 changes: 1 addition & 1 deletion keywords.json → src/tako_query_filter/keywords.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
keywords = [
"f674a8c2fb0cae1fa204bf7e6ba9e9ef",
"f3d7e7f16862091754e23c303870f259",
"4ca30d0053831e6f6d8104c312ab8017",
Expand Down