原创 [Pytorch --- 4] Roberta + 其他模型,固定Roberta層訓練時,驗證集損失不變

背景 在訓練某個神經網絡時,需要驗證後續模型的效果,因此嘗試將Roberta層的模型參數固定,代碼如下: # 固定Roberta層 freeze_layers = ['roberta.embeddings', 'roberta.enco

原创 [Pytorch --- 5] load_state_dict 報錯: KeyError: 'unexpected key roberta.xxx'

背景 在調用模型參數時,發現parameter key無法匹配 解決方案 修改代碼如下: # roberta new_state_dict = OrderedDict() for k, v in state_dict.items():

原创 [Pytorch --- 3] BUG: Roberta 多分類結果標籤權威0

問題 RobertaForMultipleChoice 執行多分類問題時,預測的label都是0 def init_adamw_optimizer(args, model, train_dataloader): t_total

原创 [算法 --- 14] 歸併排序

基本思路 # include<iostream> # include<queue> # include<string> using namespace std; // 合併兩個有序數列 void merge(vector<int>

原创 [Pytorch -- 2] masked_fill函數使用

代碼如下 import torch attn = torch.randn(3, 3) # tensor([[-0.5928, 0.9060, 1.6383], # [-0.1666, 0.6266, 0.651

原创 [Git 教程 --- 2] 關聯遠程倉庫出現remote: Repository not found.

原因 之前設置Git 免密碼登錄 git config --global credential.helper store //保存用戶名密碼 但若需要關聯不同的github賬號對應的倉庫,則無法建立連接 按照以下步驟,取消保存用戶名和密

原创 [C++ --- 3] char, char*, char[], int與string的轉換

char to string string char2str(char c) { // char c = 'a'; string str; str.push_back(c); return str; }

原创 [劍指offer刷題 --- 26] 正則表達式匹配

基本思路 假設‘.', '*'都不存在,則逐個字符比較 假設只存在'.',則按照以下思路考慮 相等: *str == *pattern  || *str != '\0' && *pattern == '.' ,則繼續匹配下一個字符,即ma

原创 [劍指offer刷題 --- 25] 機器人的運動範圍

基本思路 class Solution { public: int sum_num(int n) { int sum = 0; while (n != 0) { sum =

原创 [算法13] 常用查找算法

順序查找 折半查找/二分查找 插值查找 斐波拉契查找 二叉樹查找(二叉樹搜索,2-3查找樹,紅黑樹,B樹和B+樹) 哈希查找 分塊查找

原创 [劍指offer刷題 --- 22] 數組中的逆序對

基本思路 從左向右依次掃描,當掃描到某個數字時,將該數字與該數字後面的所有元素進行比較,此時算法複雜度爲,會出現爆內存的情況。 int InversePairs(vector<int> data) { if (data.size

原创 [算法 11] 位運算 n & (n - 1) 的解析與應用

背景 回顧常見的位運算 含義 C語言 例子 按位與 a & b   按位或 a | b   按位異或 a ^ b   按位取反 ~a   左移 a << b   帶符號右移 a >> b   n&(n-1)作用:將n的

原创 [算法12] 常用排序算法

冒泡排序 --- 雞尾酒排序 選擇排序 插入排序 ---二分插入排序 ---歸併排序 快速排序 堆排序 歸併排序 三數取中法  

原创 [劍指offer刷題 --- 23] 把字符串轉換成整數

基本思路 int StrToInt(string str) { if (str.empty()) return 0; int flag = 1; int i = 0; int time =

原创 [劍指offer刷題 --- 21] 二進制中1的個數

1. 基本思路 int Number1(int n) { int count = 0; while (n != 0) { if (n % 2 == 1) count = count