abc.ABCMeta 是一个metaclass,用于在Python程序中创建抽象基类。
在理解元类之前,您需要掌握Python的类。 Python从Smalltalk语言中借用了一个非常特殊的类概念。 在大多数语言中,类只是描述如何生成对象的代码段。 在Python中也是如此: https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python(e-satis的回答)
abc.ABCMeta 是一个metaclass,用于在Python程序中创建抽象基类。
在理解元类之前,您需要掌握Python的类。 Python从Smalltalk语言中借用了一个非常特殊的类概念。 在大多数语言中,类只是描述如何生成对象的代码段。 在Python中也是如此: https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python(e-satis的回答)
select 要统计的列名,count(*) from table
group by 要统计的列名
order by count(*) desc
https://www.kaggle.com/riblidezso/finetune-xlm-roberta-on-jigsaw-test-data-with-mlm
def prepare_mlm_input_and_labels(X):
# 15% BERT masking
inp_mask = np.random.rand(*X.shape)<0.15
# do not mask special tokens
inp_mask[X<=2] = False
# set targets to -1 by default, it means ignore
labels = -1 * np.ones(X.shape, dtype=int)
[1] 6月23日比赛结束
[2] 预训练模型框架
[3] 数据增强,类别平衡
[4] 工具分享-github,gist
[option] 基础模型
数据增强 类别平均
预训练模型 transformers
Macro F1: 将n分类的评价拆成n个二分类的评价,计算每个二分类的F1 score,n个F1 score的平均值即为Macro F1。
Micro F1: 将n分类的评价拆成n个二分类的评价,将n个二分类评价的TP、FP、RN对应相加,计算评价准确率和召回率,由这2个准确率和召回率计算的F1 score即为Micro F1。
一般来讲,Macro F1、Micro F1 高的分类效果好。Macro F1受样本数量少的类别影响大。
基本元素:
(1)若一个实例是正类,并且被预测为正类,即为真正类TP(True Positive ) (2)若一个实例是正类,但是被预测为负类,即为假负类FN(False Negative )
from torch.utils.data.sampler import Sampler
class BalanceClassSampler(Sampler):
"""Abstraction over data sampler.
Allows you to create stratified sample on unbalanced classes.
"""
def __init__(self, labels: List[int], mode: str = "downsampling"):
"""
oss连接工具 IO | |
odps读table | |
pytorch训练/测试 读odps表 dataset | |
最强文章 https://neptune.ai/blog/data-augmentation-nlp
class SynthesicOpenSubtitlesTransform(NLPTransform):
def __init__(self, always_apply=False, p=0.5):
super(SynthesicOpenSubtitlesTransform, self).__init__(always_apply, p)
df = pd.read_csv(f'{ROOT_PATH}/input/open-subtitles-toxic-pseudo-labeling/open-subtitles-synthesic.csv', index_col='id')[['comment_text', 'toxic', 'lang']]
df = df[~df['comment_text'].isna()]
df['comment_text'] = df.parallel_apply(lambda x: clean_text(x['comment_text'], x['lang']), axis=1)
df = df.drop_duplicates(subset='comment_text')