This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Very verbose implementation for finding topk with minimum comparison | |
https://stackoverflow.com/questions/4956593/optimal-algorithm-for-returning-top-k-values-from-an-array-of-length-n | |
""" | |
from __future__ import annotations | |
import dataclasses | |
import enum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import itertools | |
Distribution = dict[tuple[int, int], int] # {(#wins, #loss): #players} | |
State = tuple[float, Distribution] # (prob, dist) | |
def sum_counter(counters): | |
s = collections.Counter() | |
for c in counters: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Parse command line arguments using getopts | |
while getopts ":s:t:" opt; do | |
case $opt in | |
s) | |
source_dir="$OPTARG" | |
;; | |
t) | |
target_path="$OPTARG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copied from sentence-transformers / sentence_transformers/evaluation/BinaryClassificationEvaluator.py | |
""" | |
def find_best_f1_and_threshold(scores, labels, high_score_more_similar: bool): | |
assert len(scores) == len(labels) | |
scores = np.asarray(scores) | |
labels = np.asarray(labels) | |
rows = list(zip(scores, labels)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
class Classifier(nn.Module): | |
def __init__(self, pretrained_linear: nn.Linear): | |
super().__init__() | |
assert pretrained_linear.bias is not None # changeable | |
self.linear = nn.Linear( | |
in_features=pretrained_linear.in_features, | |
out_features=pretrained_linear.out_features, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union, Tuple, List, Dict | |
import numpy as np | |
import onnx | |
import onnxruntime as ort | |
import torch | |
import torch.nn as nn | |
def torch2onnx( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import logging | |
import time | |
logger = logging.getLogger(__name__) | |
def pretty_time(t): | |
if t < 1: | |
return f'{t * 1000:.1f} ms' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import uuid | |
from typing import Dict | |
import numpy as np | |
import tritonclient | |
import tritonclient.grpc as grpcclient | |
import tritonclient.utils.shared_memory as shm | |
ShmHandle = collections.namedtuple( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.math3.distribution.TDistribution; | |
import org.apache.commons.math3.linear.RealMatrix; | |
import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; | |
import org.apache.commons.math3.util.FastMath; | |
import java.util.Arrays; | |
public class MyOLSMultipleLinearRegression extends OLSMultipleLinearRegression { | |
/** | |
* <p>Calculates the two-tailed p-values for the t-statistics for regression parameters. |