My code is like that:
TEXT = data.Field(batch_first=True,include_lengths=True)
LABEL = data.LabelField(dtype = torch.float,batch_first=True)
fields = [(None, None),('text',TEXT),('label', LABEL)]
training_data=data.TabularDataset(path = 'drive/My Drive/Colab Notebooks/Heyhey/scaled_data_235.csv',format = 'csv',fields = fields,skip_header = True)
print(vars(training_data.examples[0]))
output of training_data.examples[0]:
{'text': ['今夜', 'スパムカレー', '゚', '゚ノハイサイ', 'tcokSafSSrg', 'フリーランス'...], 'label': '0.7647058823529411'}
import random
train_data, valid_data = training_data.split(split_ratio=0.7, random_state = random.seed(SEED))
#initialize glove embeddings
TEXT.build_vocab(train_data,min_freq=3)
LABEL.build_vocab(train_data)
#No. of unique tokens in text
print("Size of TEXT vocabulary:",len(TEXT.vocab))
#No. of unique tokens in label
print("Size of LABEL vocabulary:",len(LABEL.vocab))
#Commonly used words
print(TEXT.vocab.freqs.most_common(10))
#Word dictionary
print(TEXT.vocab.stoi)
Size of TEXT vocabulary: 13365 Size of LABEL vocabulary: 16 [('ない', 4225), ('れ', 1901), ('なっ', 997), ('️', 963), ('なく', 702), ('いい', 658), ('フォロー', 631), ('だっ', 618), ('✨', 607), ('日本', 550)] defaultdict(<function _default_unk_index at 0x7f2f19709b70>, {'': 0, '': 1, 'ない': 2, ...,\U0001f9d0': 13364})
#check whether cuda is available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
#set batch size
BATCH_SIZE = 8
#Load an iterator
train_iterator, valid_iterator = data.BucketIterator.splits(
(train_data, valid_data),
batch_size = BATCH_SIZE,
sort_key = lambda x: len(x.text),
sort_within_batch=True,
device = device)
for batch in train_iterator:
print(batch.label)
Batch.label returns like that:
tensor([0., 2., 1., 6., 1., 7., 4., 0.], device='cuda:0') tensor([2., 0., 8., 0., 6., 2., 4., 3.], device='cuda:0') ...
My question is that: first batch. label value supposed to return as '0.7647058823529411 but it returns an integer between 0 and 16. I try to make regression but it seems but BatchIterator converts it to classifier. How can I return 0.764 instead of [0-16]?