Update pyai.py
Browse files
pyai.py
CHANGED
@@ -3,6 +3,7 @@ import whisper
|
|
3 |
import numpy as np
|
4 |
from torch import nn
|
5 |
from torch import Tensor
|
|
|
6 |
from sklearn.tree import DecisionTreeRegressor
|
7 |
|
8 |
|
@@ -60,6 +61,15 @@ class PyAI:
|
|
60 |
else:
|
61 |
soft = nn.Softmax(dim=1).to(self.GPU)(x)
|
62 |
return soft
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def decisionTree(self, trainX: list, trainY: list, words: list):
|
65 |
w = np.array([len(a) for a in words]).reshape(-1, 1)
|
@@ -149,4 +159,13 @@ class PyAI:
|
|
149 |
|
150 |
def getPartOfSpeech(self, text: str):
|
151 |
POS = spacy.load("en_core_web_sm")
|
152 |
-
return POS(text)[0].tag_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
from torch import nn
|
5 |
from torch import Tensor
|
6 |
+
from transformers import pipeline
|
7 |
from sklearn.tree import DecisionTreeRegressor
|
8 |
|
9 |
|
|
|
61 |
else:
|
62 |
soft = nn.Softmax(dim=1).to(self.GPU)(x)
|
63 |
return soft
|
64 |
+
|
65 |
+
def Sigmoid(self, x: list | Tensor):
|
66 |
+
if isinstance(x, list):
|
67 |
+
tensor = Tensor(x, 1).to(self.GPU)
|
68 |
+
sigmod = nn.Sigmoid().to(self.GPU)(tensor)
|
69 |
+
return sigmod
|
70 |
+
else:
|
71 |
+
sigmod = nn.Sigmoid().to(self.GPU)(x)
|
72 |
+
return sigmod
|
73 |
|
74 |
def decisionTree(self, trainX: list, trainY: list, words: list):
|
75 |
w = np.array([len(a) for a in words]).reshape(-1, 1)
|
|
|
159 |
|
160 |
def getPartOfSpeech(self, text: str):
|
161 |
POS = spacy.load("en_core_web_sm")
|
162 |
+
return POS(text)[0].tag_
|
163 |
+
|
164 |
+
def BERT(self, text: str, model: str = "bert-base-uncased"):
|
165 |
+
BERT = pipeline("fill-mask", model=model)
|
166 |
+
return BERT(text)
|
167 |
+
|
168 |
+
class Transformers:
|
169 |
+
def __init__(self, text: str, typeOfOperation: str = "text-generation", model: str = "gpt2"):
|
170 |
+
transformer = pipeline(typeOfOperation, model=model)
|
171 |
+
return transformer(text)
|