Repository for Natural Language Processing
pnageshkar / nlp Goto Github PK
View Code? Open in Web Editor NEWNatural Language Processing
Natural Language Processing
# Filter out records ( values in clean_body and tags) that have atleast one of the top tags
x=[] # To store the filtered clean_body values
y=[] # to store the corresponding tags
# Convert to list data type
lst_top_tags = list(top_tags)
for i in range(len(df['tags'])):
temp=[]
for tag in df['tags'][i]:
if tag in lst_top_tags:
temp.append(tag)
if(len(temp)>1):
x.append(df['Clean_Body'][i])
y.append(temp)
Hello, I'm Min, an NLP student!
I found you on the web below and It's helping a student like me a lot.
https://medium.com/analytics-vidhya/multi-label-text-classification-using-transformers-bert-93460838e62b
However, I tried to run your code from colab and got the error as below.
trainer.fit(model, QTdata_module)
ValueError: Target size (torch.Size([16, 1])) must be the same as input size (torch.Size([16, 10]))
You can also see the code that i run below.
https://colab.research.google.com/drive/1Ai9b5rhXrixpmnqiRp8Y3RPEW364jONu#scrollTo=rA8LfjSHpDSm
there's something to do with shape.. but I'm not sure what's wrong..
would you be able to tell me what the problem is?
Thank you for your work Sir!
prepend
model = model.to(device)
# Put model in evaluation mode
model.eval()
# Tracking variables
pred_outs, true_labels = [], []
#i=0
# Predict
for batch in pred_dataloader:
# Add batch to GPU
batch = tuple(t.to(device) for t in batch)
# Unpack the inputs from our dataloader
b_input_ids, b_attn_mask, b_labels = batch
with torch.no_grad():
# Forward pass, calculate logit predictions
pred_out = model(b_input_ids,b_attn_mask)
pred_out = torch.sigmoid(pred_out)
# Move predicted output and labels to CPU
pred_out = pred_out.detach().cpu().numpy()
label_ids = b_labels.to('cpu').numpy()
#i+=1
# Store predictions and true labels
#print(i)
#print(outputs)
#print(logits)
#print(label_ids)
pred_outs.append(pred_out)
true_labels.append(label_ids)
Hi,
the predict function has a dependency to the MultiLabelBinarizer, which is used within training the model.
Can you give us an example where the predict function is independently usable?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.