folder-classifier 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/PKG-INFO +1 -1
- folder_classifier-0.2.2/folder_classifier/classifier.py +25 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier/dto.py +2 -7
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/PKG-INFO +1 -1
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/setup.cfg +1 -1
- folder_classifier-0.2.0/folder_classifier/classifier.py +0 -34
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/README.md +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier/__init__.py +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier/app.py +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier/deploy.py +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier/util.py +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/SOURCES.txt +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/dependency_links.txt +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/top_level.txt +0 -0
- {folder_classifier-0.2.0 → folder_classifier-0.2.2}/pyproject.toml +0 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
from typing import Tuple
|
2
|
+
import torch
|
3
|
+
from transformers import pipeline
|
4
|
+
from folder_classifier.dto import Listing
|
5
|
+
|
6
|
+
|
7
|
+
classifier = None
|
8
|
+
|
9
|
+
|
10
|
+
def predict(listing: Listing) -> Tuple[str, float]:
|
11
|
+
global classifier
|
12
|
+
if classifier is None:
|
13
|
+
classifier = pipeline(
|
14
|
+
"text-classification",
|
15
|
+
model="/mnt/cluster_storage/models/corto-ai/ModernBERT-large-folder-classifier",
|
16
|
+
torch_dtype=torch.bfloat16,
|
17
|
+
device="cuda"
|
18
|
+
)
|
19
|
+
text = "\n".join(listing.items)
|
20
|
+
prediction = classifier(text)
|
21
|
+
predicted_label = prediction[0]["label"]
|
22
|
+
confidence = prediction[0]["score"]
|
23
|
+
return predicted_label, confidence
|
24
|
+
|
25
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
from textwrap import dedent
|
4
|
-
from typing import List, Union, Literal
|
4
|
+
from typing import List, Union, Literal, Optional
|
5
5
|
|
6
6
|
from pydantic import BaseModel, Field, confloat
|
7
7
|
|
@@ -24,7 +24,7 @@ class Folder(BaseModel):
|
|
24
24
|
name: str
|
25
25
|
type: Literal["folder"]
|
26
26
|
# Discriminated union: 'type' field is used to select between File and Folder
|
27
|
-
items: List[Union[File, Folder]] = Field(default_factory=list)
|
27
|
+
items: Optional[List[Union[File, Folder]]] = Field(default_factory=list)
|
28
28
|
model_config = {
|
29
29
|
"json_schema_extra": {
|
30
30
|
# Override the OpenAPI example to avoid the default 'string' entry
|
@@ -49,11 +49,6 @@ class Listing(BaseModel):
|
|
49
49
|
Folder.model_rebuild()
|
50
50
|
FolderClassificationRequest = Union[Folder, Listing]
|
51
51
|
|
52
|
-
|
53
|
-
class ItemsRequest(BaseModel):
|
54
|
-
items: List[Union[File, Folder]]
|
55
|
-
|
56
|
-
|
57
52
|
class FolderClassificationResponse(BaseModel):
|
58
53
|
category: Literal["matter", "other"]
|
59
54
|
confidence: confloat(ge=0.0, le=1.0)
|
@@ -1,34 +0,0 @@
|
|
1
|
-
from typing import Tuple
|
2
|
-
|
3
|
-
import numpy as np
|
4
|
-
import torch
|
5
|
-
from transformers import pipeline
|
6
|
-
|
7
|
-
from folder_classifier.dto import Listing
|
8
|
-
|
9
|
-
classifier = pipeline(
|
10
|
-
"zero-shot-classification",
|
11
|
-
model="MoritzLaurer/ModernBERT-large-zeroshot-v2.0",
|
12
|
-
torch_dtype=torch.bfloat16,
|
13
|
-
device="cuda"
|
14
|
-
)
|
15
|
-
|
16
|
-
candidate_labels = ["legal_matter", "other"]
|
17
|
-
|
18
|
-
def predict(listing: Listing) -> Tuple[str, float]:
|
19
|
-
text = "\n".join(listing.items)
|
20
|
-
hypothesis_template = "This list of files is about {}"
|
21
|
-
prediction = classifier(
|
22
|
-
text,
|
23
|
-
candidate_labels,
|
24
|
-
hypothesis_template=hypothesis_template,
|
25
|
-
multi_label=False,
|
26
|
-
)
|
27
|
-
scores = np.array(prediction["scores"], dtype=float)
|
28
|
-
highest_ix = np.argmax(scores)
|
29
|
-
predicted_label = prediction["labels"][highest_ix]
|
30
|
-
confidence = float(scores[highest_ix])
|
31
|
-
prediction = "matter" if predicted_label == "legal_matter" else "other"
|
32
|
-
return prediction, confidence
|
33
|
-
|
34
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/dependency_links.txt
RENAMED
File without changes
|
{folder_classifier-0.2.0 → folder_classifier-0.2.2}/folder_classifier.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|