Views
No views yet
'Adult', 'Arts_and_Entertainment', 'Autos_and_Vehicles', 'Beauty_and_Fitness', 'Books_and_Literature', 'Business_and_Industrial', 'Computers_and_Electronics', 'Finance', 'Food_and_Drink', 'Games', 'Health', 'Hobbies_and_Leisure', 'Home_and_Garden', 'Internet_and_Telecom', 'Jobs_and_Education', 'Law_and_Government', 'News', 'Online_Communities', 'People_and_Society', 'Pets_and_Animals', 'Real_Estate', 'Science', 'Sensitive_Subjects', 'Shopping', 'Sports', 'Travel_and_Transportation'q Directions
1. Mix 2 flours and baking powder together
2. Mix water and egg in a separate bowl. Add dry to wet little by little
3. Heat frying pan on medium
4. Pour batter into pan and then put blueberries on top before flipping
5. Top with desired toppings!Food_and_Drink1import torch
2from torch import nn
3from transformers import AutoModel, AutoTokenizer, AutoConfig
4from huggingface_hub import PyTorchModelHubMixin
5
6class CustomModel(nn.Module, PyTorchModelHubMixin):
7 def __init__(self, config):
8 super(CustomModel, self).__init__()
9 self.model = AutoModel.from_pretrained(config["base_model"])
10 self.dropout = nn.Dropout(config["fc_dropout"])
11 self.fc = nn.Linear(self.model.config.hidden_size, len(config["id2label"]))
12
13 def forward(self, input_ids, attention_mask):
14 features = self.model(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
15 dropped = self.dropout(features)
16 outputs = self.fc(dropped)
17 return torch.softmax(outputs[:, 0, :], dim=1)
18
19# Setup configuration and model
20config = AutoConfig.from_pretrained("nvidia/domain-classifier")
21tokenizer = AutoTokenizer.from_pretrained("nvidia/domain-classifier")
22model = CustomModel.from_pretrained("nvidia/domain-classifier")
23model.eval()
24
25# Prepare and process inputs
26text_samples = ["Sports is a popular domain", "Politics is a popular domain"]
27inputs = tokenizer(text_samples, return_tensors="pt", padding="longest", truncation=True)
28outputs = model(inputs["input_ids"], inputs["attention_mask"])
29
30# Predict and display results
31predicted_classes = torch.argmax(outputs, dim=1)
32predicted_domains = [config.id2label[class_idx.item()] for class_idx in predicted_classes.cpu().numpy()]
33print(predicted_domains)
34# ['Sports', 'News']| Domain | PR-AUC |
|---|---|
| Adult | 0.999 |
| Arts_and_Entertainment | 0.997 |
| Autos_and_Vehicles | 0.997 |
| Beauty_and_Fitness | 0.997 |
| Books_and_Literature | 0.995 |
| Business_and_Industrial | 0.982 |
| Computers_and_Electronics | 0.992 |
| Finance | 0.989 |
| Food_and_Drink | 0.998 |
| Games | 0.997 |
| Health | 0.997 |
| Hobbies_and_Leisure | 0.984 |
| Home_and_Garden | 0.997 |
| Internet_and_Telecom | 0.982 |
| Jobs_and_Education | 0.993 |
| Law_and_Government | 0.967 |
| News | 0.918 |
| Online_Communities | 0.983 |
| People_and_Society | 0.975 |
| Pets_and_Animals | 0.997 |
| Real_Estate | 0.997 |
| Science | 0.988 |
| Sensitive_Subjects | 0.982 |
| Shopping | 0.995 |
| Sports | 0.995 |
| Travel_and_Transportation | 0.996 |
| Mean | 0.9873 |