pt文件的權重的加載(推薦保存成pt文件)
先pycharm文件之間根據設置斷點,debug后抄參數,
利用這些參數初始化一個模型
torch.load加載權重,然后使用模型.load_state_dict(torch.load(r'.pt'))
然后就可以預測了,pycharm的數據傳輸很難,最好保存成文件用的時候再打開
pd.read_csv()是個dataframe框架
兩個dataframe可以通過merge連接起來,on=‘連接的列,按值連接’
dataframe.to_csv()即可生成csv
csv空白格輸入字,點擊后Ctrl+shift+向下鍵,選擇性粘貼,可以批量運算
數據預處理dataset最應該搞清楚,數據內容是什么應該搞清楚
batch進去出去后,可能出來的數據和原本的數據的先后順序不一樣
改代碼原則,等價替換,變量的性質一樣,即可替換
dataframe.shape[0]行
dataframe.shape[1]列
模型最后loss在1.512
得分在0.573,大部分情緒都預測的無情緒傾向,對正面情緒預測還行,負面情緒和無情緒傾向不能很好的區分
目前發現feilds一定的處理規則
根據兩個feilds(text,label)送到get_dataset中起作用,
使用以下feild規則
[("微博id", None), # we won't be needing the id, so we pass in None as the field
("微博中文內容", text_field), ("情感傾向", label_field)]
此時的examples已經起作用了,是處理過的格式,裝到dataset對象里
用iterator裝成batch格式,
初始化一個RNN
使用rnn進行訓練,每輪訓練一次,loss 用criterion傳進去predict和answer
詞向量的權重是個問題
并不能很好的使用已有的權重模型,太大了,800W+的數量太高,不適合跑
enumerate返回一個(index,可遍歷序列的一個元素)
在中文大語料庫上訓練word2vector
以后最好在訓練時加上tqdm以可視化訓練進度
tqdm嵌套在enumerate里面
pytorch中的squential可以拼接好幾個網絡層
訓練集上
-
類別以及個數
1 57619
2 25392
0 16902
f1_score計算公式
第一輪
第二輪
第三輪
第四輪
第五輪
第六輪
第七輪
實際上pre或者recall的返回值都是針對相應類的值,看樣子對原本樣本數的依賴更小點,而且loss也在下降
dataframe可以使用每列進行map運算,因為每列相當于series,例如
dataframe[a]=dataframe.a.map(lambda x:x**2)
At the most basic level, a loss function quantifies how “good” or “bad” a given predictor is at classifying the input data points in a dataset.
The smaller the loss, the better a job the classifier is at modeling the relationship between the input data and the output targets.
That said, there is a point where we can overfit our model — by modeling the training data too closely, our model loses the ability to generalize.
英語可逆性invertibility可逆性
避免過擬合的方法,1.減少模型變量的數量。2正則化regularization,即罰函數法,對加入參數對loss的影響,減少參數的大小,使得模型平滑。
why sometimes is valid loss lower than train loss:
Regularization methods often sacrifice training accuracy to improve validation/testing accuracy — in some cases that can lead to your validation loss being lower than your training loss.