我正在按照 HuggingFace 的序列分类教程学习 NLP https://huggingface.co/transformers/custom_datasets.html#sequence-classification-with-imdb-reviews
原始代码运行没有问题。但是,当我尝试加载不同的标记生成器(例如来自 的标记生成器)时google/bert_uncased_L-4_H-256_A-4,会出现以下警告:
Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.
from transformers import AutoTokenizer
from pathlib import Path
def read_imdb_split(split_dir):
split_dir = Path(split_dir)
texts = []
labels = []
for label_dir in ["pos", "neg"]:
for text_file in (split_dir/label_dir).iterdir():
texts.append(text_file.read_text())
labels.append(0 if label_dir is "neg" else 1)
return texts[:50], labels[:50]
if __name__ == '__main__':
test_texts, test_labels = read_imdb_split('aclImdb/test')
tokenizer …Run Code Online (Sandbox Code Playgroud) 我是 Java 新手,最近我了解到有时深度复制 Collection 并对其进行不可修改的视图很重要,这样里面的数据才能保持安全和不变。当我尝试练习这个(unmodifiableMap2)时,我收到了来自IDEA的警告
unmodifiableMap 可以替换为 'Map.copyOf' 调用
这对我来说是连线的,因为我认为 unmodifiableMap 不仅仅是底层地图的副本。此外,当我尝试以另一种方式(unmodifiableMap1)创建相同的 unmodifiableMap 时,不会弹出警告!
我应该如何理解 IDEA 的这种行为?
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class test {
public static void main(String[] args) {
Map<Integer, Integer> map = new HashMap<>();
map.put(1,1);
map.put(2,2);
Map<Integer, Integer> map1 = new HashMap<>(map);
Map<Integer, Integer> unmodifiableMap1 = Collections.unmodifiableMap(map1);
Map<Integer, Integer> unmodifiableMap2 = Collections.unmodifiableMap(new HashMap<>(map););
}
}
Run Code Online (Sandbox Code Playgroud)