text stringlengths 1 93.6k |
|---|
class Classifier():
|
def __init__(self, params):
|
self.classifier = params.classifier
|
self.k_shot = params.k_shot
|
def predict(self, data_result):
|
# data_result: dict
|
# classifier_type:
|
# 1. protoNet
|
# 2. SVM
|
# 3. KNN
|
# 4. logistic regression
|
# 5. classifier NN
|
if (self.classifier == 'protonet'):
|
predicted_y,loss = one_shot_classifier_prototype_lowerdim(data_result)
|
elif (self.classifier == 'SVM'):
|
classifier_SVM = SVC(C=10)
|
classifier_SVM.fit(data_result['support_feature'], data_result['support_y'])
|
predicted_y = classifier_SVM.predict(data_result['query_feature'])
|
elif (self.classifier == 'LR'):
|
classifier_LR = LogisticRegression()
|
classifier_LR.fit(data_result['support_feature'], data_result['support_y'])
|
predicted_y = classifier_LR.predict(data_result['query_feature'])
|
elif (self.classifier == 'KNN'):
|
classifier_KNN = KNeighborsClassifier(n_neighbors= self.k_shot)
|
classifier_KNN.fit(data_result['support_feature'],data_result['support_y'])
|
predicted_y = classifier_KNN.predict(data_result['query_feature'])
|
elif(self.classifier == 'cosine'):
|
distance_cosine_tensor = cosine_dist(data_result['query_feature'],data_result['support_feature'])
|
#print('tensor cosine dist:', distance_cosine_tensor.size())
|
#distance_cosine = cosine_similarity(data_result['query_feature'].detach().cpu().numpy(),data_result['support_feature'].detach().cpu().numpy())
|
#print('numpyt cosine dist:', distance_cosine)
|
probability = torch.nn.functional.softmax(distance_cosine_tensor, dim=-1)
|
#print('tensor cosine dist:', distance_cosine_tensor)
|
query_y = data_result['query_y']
|
import torch.nn as nn
|
criterion = nn.CrossEntropyLoss()
|
probability = probability.unsqueeze(0)
|
label= query_y.long()
|
#print('pro:', probability, 'label:',label)
|
loss = criterion(probability, label)
|
probability = probability.data.cpu().numpy()
|
predicted_y = np.argmax(probability, axis=1)
|
#predicted_y = np.argsort(-distance_cosine)
|
#predicted_y = predicted_y[:,0]
|
else:
|
print('classifier type error.')
|
return predicted_y,loss
|
if __name__=='__name__':
|
myClassifier=classifier()
|
# <FILESEP>
|
"""
|
___ __ _
|
/ __\ ___ _ __ / _|(_) __ _
|
/ / / _ \ | '_ \ | |_ | | / _` |
|
/ /___ | (_) || | | || _|| || (_| |
|
\____/ \___/ |_| |_||_| |_| \__, |
|
|___/
|
"""
|
# Twitter API credentials. If you need any help have a look at README.md
|
twitter_credentials = {
|
"consumer_key": '',
|
"consumer_secret": '',
|
"access_token": '',
|
"access_secret": '',
|
}
|
# DON'T WRITE ANYTHING IN CAPS, AS THE BOT AUTOMATICALLY FLATTERS ALL INPUT TEXTS. THUS ANY WORD WITH CAPS WON'T BE RECOGNIZED
|
# Tags that Twitter will use to look up our tweets. Really important as all the script will be based on them
|
search_tags = ["giveaway", "contest", "sorteo", "to win"]
|
# Don't start the bot if friends weren't correctly retrieved
|
wait_retrieve = False
|
# Enable this if you want the bot to send a DM in case it detects any message_tags
|
use_msgs = False
|
#Ignore tweets that contain any of these words
|
BadList = ["throat","bone","naked","selfie","photo","onlyfans","nude","+18","femdom","fendom","whatsapp","sex","xxx","daddy","mommy","sugar","vid","#imgxnct","pic","tits" ,"booty" ,"boob", "freenude","cum", "dick" ,"gay" ,"onlyfans.com","hot", "ass", "fuck", "suck", "cock", "lick","pussy" ]
|
# What words will the bot check in order to retweet a tweet. It's important because if the bot doesnt
|
# recognize any, it will skip the whole tweet and it wont check if it has to like, msg, or follow
|
retweet_tags = ["retweet", "retweetea", "retwitea", "rt"]
|
# What words will trigger to send the author a DM with a random message_text
|
message_tags = ["message", "dm"]
|
# What words will the bot check in order to follow the author of the tweet plus all the users mentioned in the text
|
# (we assume that a retweet tag was recognized)
|
follow_tags = ["follow", "fl", "sigue", "seguir", "siguenos"]
|
# What words will the bot look for in order to like a tweet (it also needs to contain a retweet tag)
|
like_tags = ["like", "fav", "favorite"]
|
# These are supposed to be random msgs the bot would send if DMing is required
|
message_text = ["I want to enter to the giveaway!", "Hope to win :D"]
|
# Add to this list all the users whose contests (actually tweets that contain retweet_tags keywords) the script will
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.