Views
No views yet
fine-tuned on LinkedCringe v0.2 from intfloat/e5-small
# numeric id: text label
{
1: 'cringe',
2: 'relevant',
3: 'info',
4: 'noise'
}python -m pip install setfit1from setfit import SetFitModel
2
3# Download from Hub and run inference
4model = SetFitModel.from_pretrained("pszemraj/e5-small-LinkedCringe-setfit-skl-20it-2e")
5# Run inference
6preds = model(["i loved the spiderman movie!", "pineapple on pizza is the worst 🤮"])
7
8# manually refer to labels above
9preds1from setfit import SetFitModel
2from typing import List, Dict
3
4
5class PostClassifier:
6 DEFAULT_ID2LABEL = {1: "cringe", 2: "relevant", 3: "info", 4: "noise"}
7
8 def __init__(
9 self,
10 model_id: str = "pszemraj/e5-small-LinkedCringe-setfit-skl-20it-2e",
11 id2label: Dict[int, str] = None,
12 ):
13 """Initialize PostClassifier with model name and/or label mapping."""
14 self.model = SetFitModel.from_pretrained(model_id)
15 self.id2label = id2label if id2label else self.DEFAULT_ID2LABEL
16
17 def classify(self, texts: List[str]) -> List[str]:
18 """Classify list of texts, return list of corresponding labels."""
19 preds = self.model(texts)
20 return [self.id2label[int(pred)] for pred in preds]
21
22 def predict_proba(self, texts: List[str]) -> List[Dict[str, float]]:
23 """Predict label probabilities for a list of texts, return a list of probability dictionaries."""
24 proba = self.model.predict_proba(texts)
25 return [
26 {self.id2label.get(i + 1, "Unknown"): float(pred) for i, pred in enumerate(pred)}
27 for pred in proba
28 ]
29
30 def __call__(self, texts: List[str]) -> List[str]:
31 """Enable class instance to act as a function for text classification."""
32 return self.classify(texts)1# import PostClassifier if you defined it in another script etc
2model_name="pszemraj/e5-small-LinkedCringe-setfit-skl-20it-2e"
3classifier = PostClassifier(model_name)
4
5# classify some posts (these should all be cringe maaaaybe noise)
6posts = [
7 "🚀 Innovation is our middle name! We're taking synergy to new heights and disrupting the market with our game-changing solutions. Stay tuned for the next paradigm shift! 💥 #CorporateRevolution #SynergisticSolutions",
8 "🌟 Attention all trailblazers! Our cutting-edge product is the epitome of excellence. It's time to elevate your success and ride the wave of unparalleled achievements. Join us on this journey towards greatness! 🚀 #UnleashYourPotential #SuccessRevolution",
9 "🌍 We're not just a company, we're a global force for change! Our world-class team is committed to revolutionizing industries and making a lasting impact. Together, let's reshape the future and leave a legacy that will be remembered for ages! 💪 #GlobalTrailblazers #LegacyMakers",
10 "🔥 Harness the power of synergy and unlock your true potential with our transformative solutions. Together, we'll ignite a fire of success that will radiate across industries. Join the league of winners and conquer new frontiers! 🚀 #SynergyChampions #UnleashThePowerWithin",
11 "💡 Innovation alert! Our visionary team has cracked the code to redefine excellence. Get ready to be blown away by our mind-boggling breakthroughs that will leave your competitors in the dust. It's time to disrupt the status quo and embrace the future! 🌟 #InnovationRevolution #ExcellenceUnleashed",
12 "🌐 Welcome to the era of limitless possibilities! Our revolutionary platform will empower you to transcend boundaries and achieve unprecedented success. Together, let's shape a future where dreams become realities and ordinary becomes extraordinary! ✨ #LimitlessSuccess #DreamBig",
13 "💥 Brace yourselves for a seismic shift in the industry! Our game-changing product is set to revolutionize the way you work, think, and succeed. Say goodbye to mediocrity and join the league of pioneers leading the charge towards a brighter tomorrow! 🚀 #IndustryDisruptors #PioneeringSuccess",
14 "🚀 Attention all innovators and disruptors! It's time to break free from the chains of convention and rewrite the rulebook of success. Join us on this exhilarating journey as we create a new chapter in the annals of greatness. The sky's not the limit—it's just the beginning! 💫 #BreakingBarriers #UnleashGreatness",
15 "🌟 Unlock the secret to unprecedented achievements with our exclusive formula for success. Our team of experts has distilled years of wisdom into a powerful elixir that will propel you to the zenith of greatness. It's time to embrace the extraordinary and become a legend in your own right! 💥 #FormulaForSuccess #RiseToGreatness",
16 "🔑 Step into the realm of infinite possibilities and seize the keys to your success. Our groundbreaking solutions will unlock doors you never knew existed, propelling you towards a future filled with limitless growth and prosperity. Dare to dream big and let us be your catalyst for greatness! 🚀 #UnlockYourPotential #LimitlessSuccess"
17]
18
19
20post_preds = classifier(posts)
21print(post_preds)***** Running evaluation *****
{'accuracy': 0.8,
'based_model_id': 'intfloat/e5-small',
'tuned_model_id': 'e5-small-LinkedCringe-setfit-skl-20it-2e'}
# 10-post results
['cringe',
'cringe',
'info',
'cringe',
'cringe',
'cringe',
'cringe',
'cringe',
'cringe',
'cringe']Note: this is forsetfitand not this checkpoint.
1@article{https://doi.org/10.48550/arxiv.2209.11055,
2doi = {10.48550/ARXIV.2209.11055},
3url = {https://arxiv.org/abs/2209.11055},
4author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
5keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
6title = {Efficient Few-Shot Learning Without Prompts},
7publisher = {arXiv},
8year = {2022},
9copyright = {Creative Commons Attribution 4.0 International}
10}