记录 Transformer 模型中几种典型位置编码的实现。
略
class RotaryPositionalEncoding(nn.Module):
在分类问题中,FocalLoss 是一种解决标签分布不均的方法,并使模型专注于学习困难样本。例如,在医学影像检测中,负样本数量显著大于正样本。FocalLoss 原始论文中只讨论了二分类任务,缺少针对多分类问题的相应实现,这里记录一下实现方法。
class MultiClassFocalLoss(nn.Module):
def __init__(self, gamma: float = 2.0, alpha: torch.Tensor = None, reduction: str = 'mean', ignore_index: int = -100):
"""
Args:
gamma (float): 调制因子,越大越关注困难样本 (γ >= 0)。
{"config":{"codeTheme":"OneDarkPro","pageThemeSyncCodeTheme":true,"openAlmightyConsole":true,"autoRun":true,"layout":"edit","keepPreviousLogs":true,"codeFontSize":14},"title":"coderun-echarts","code":{"HTML":{"language":"html","content":"<!-- 为ECharts准备一个具备大小(宽高)的Dom -->\n<div id=\"main\" style=\"width: 800px; height:600px;\"></div>","resources":[]},"CSS":{"language":"css","content":"","resources":[]},"JS":{"language":"javascript","content":"// 基于准备好的dom,初始化echarts实例\nvar myChart = echarts.init(document.getElementById(\"main\"));\n\n// 指定图表的配置项和数据\n// prettier-ignore\nconst hours = [\n '0','1星','2星','3星','4星','5星','6'\n];\n\n// prettier-ignore\nconst days = [\n '智驾车型覆盖度',\t'自动泊车',\t'记忆泊车',\t'高速LCC',\t'城区LCC',\t'高速领航辅助驾驶',\t'城区领航辅助驾驶'\n];\n\n// prettier-ignore\nconst data = [[0, 3, 1], [0, 4, 4], [0, 5, 1], [1, 4, 6], [2, 3, 1], [2, 5, 3], [3, 5, 6], [4, 4, 3], [4, 5, 3], [5, 3, 1], [5, 4, 2], [5, 5, 3], [6, 3, 1], [6, 4, 2], [6, 5, 2]];\nconst title = [];\nconst singleAxis = [];\nconst series = [];\ncon |
from concurrent.futures import as_completed | |
from concurrent.futures.process import ProcessPoolExecutor | |
import os | |
import psutil | |
import time | |
def kill_child_processes(parent_pid): | |
try: | |
parent = psutil.Process(parent_pid) |
package com.example.udf; | |
import com.google.common.base.Throwables; | |
import org.apache.hadoop.hive.ql.exec.Description; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentException; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; | |
import org.apache.hadoop.hive.ql.metadata.HiveException; | |
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; | |
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; |
# this function will be called on exceptions in any cell
def when_exception(shell, etype, evalue, tb, tb_offset=None):
# still show the error within the notebook, don't just swallow it
shell.showtraceback((etype, evalue, tb), tb_offset=tb_offset)
err_msg = f'Unexpected exception occured: {repr(evalue)}'
logger.error(err_msg)
A wrapper for Python protobuf object:
class PbMessage(object):
"""protobuf 消息的包装类,封装一些通用方法"""
def __init__(self, pb_class):
self._pb_class = pb_class
self._pb_obj = None
self._raw_msg = None