parth parekh
commited on
Commit
·
cc5ebd5
1
Parent(s):
3c4c0f5
distil bert was the best
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
-
from transformers import
|
5 |
from torch.nn.functional import softmax
|
6 |
|
7 |
app = FastAPI(
|
@@ -14,8 +14,8 @@ app = FastAPI(
|
|
14 |
class ContactDetector:
|
15 |
def __init__(self):
|
16 |
cache_dir = "/app/model_cache"
|
17 |
-
self.tokenizer =
|
18 |
-
self.model =
|
19 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
self.model.to(self.device)
|
21 |
self.model.eval()
|
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
5 |
from torch.nn.functional import softmax
|
6 |
|
7 |
app = FastAPI(
|
|
|
14 |
class ContactDetector:
|
15 |
def __init__(self):
|
16 |
cache_dir = "/app/model_cache"
|
17 |
+
self.tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased', cache_dir=cache_dir)
|
18 |
+
self.model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased', num_labels=2, cache_dir=cache_dir)
|
19 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
self.model.to(self.device)
|
21 |
self.model.eval()
|