-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added classifier for category filtering.
- Loading branch information
1 parent
df9ef6a
commit 71728a0
Showing
8 changed files
with
328 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ hntoebook_linux_amd64.zip | |
hntoebook_linux_arm64.zip | ||
hntoebook_windows_amd64.zip | ||
db | ||
|
||
models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/python | ||
from transformers import pipeline | ||
import sys | ||
|
||
classifier = pipeline("zero-shot-classification", model="models/distilbert-base-uncased-mnli") | ||
|
||
sequence = sys.argv[1] | ||
candidate_labels = sys.argv[2].split(",") | ||
|
||
res = classifier(sequence, candidate_labels, multi_label=True, truncation=False) | ||
|
||
for i, label in enumerate(candidate_labels): | ||
print("%d. %s [%.2f]" % (i, res['labels'][i], res['scores'][i])) | ||
if res['scores'][i] > 0.75: | ||
print("Keyword is True") | ||
else: | ||
print("Keyword is False") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from fastapi import FastAPI | ||
from pydantic import BaseModel, constr, conlist | ||
from typing import List | ||
from transformers import pipeline | ||
|
||
classifier = pipeline("zero-shot-classification", | ||
model="models/distilbert-base-uncased-mnli") | ||
app = FastAPI() | ||
|
||
|
||
class UserRequestIn(BaseModel): | ||
text: constr(min_length=1) | ||
labels: conlist(str, min_items=1) | ||
|
||
|
||
class ScoredLabelsOut(BaseModel): | ||
labels: List[str] | ||
scores: List[float] | ||
|
||
|
||
@app.post("/classification", response_model=ScoredLabelsOut) | ||
def read_classification(user_request_in: UserRequestIn): | ||
return classifier(user_request_in.text, user_request_in.labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
uvicorn | ||
torch | ||
fastapi | ||
pydantic | ||
typing | ||
transformers |
Oops, something went wrong.