Skip to content

Instantly share code, notes, and snippets.

View altescy's full-sized avatar
👋

Yasuhiro Yamaguchi altescy

👋
View GitHub Profile
import dataclasses
import fcntl
import json
import pickle
import shutil
import tempfile
from collections.abc import Mapping
from contextlib import contextmanager
from io import BytesIO
from os import PathLike
from typing import Generic, Hashable, Iterable, Mapping, Optional, Sequence, TypeVar
import numpy
from sklearn.base import TransformerMixin
T_Token = TypeVar("T_Token", bound=Hashable)
Self = TypeVar("Self", bound="SwemVectorizer")
class SwemVectorizer(Generic[T_Token], TransformerMixin): # type: ignore[misc]
import abc
import functools
from os import PathLike
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union
import fugashi
import minato
class Token(NamedTuple):
@altescy
altescy / spinner.py
Last active January 10, 2023 18:33
Simple spinner decorator for Python
import functools
import itertools
import sys
import threading
import time
from collections.abc import Callable, Iterable
from concurrent.futures import ThreadPoolExecutor
from typing import Any, TextIO, TypeVar
T = TypeVar("T")
@altescy
altescy / multiprocess_queue_iterator.py
Created January 8, 2023 08:15
Iterator wrapper generating values with multi-processing queue
import time
from collections.abc import Iterable, Iterator
from multiprocessing import Process, Queue
from types import TracebackType
from typing import Generic, Type, TypeVar
T = TypeVar("T")
class NumberIterator:
import dataclasses
import datetime
import re
import socket
import socketserver
import time
class config:
SOCKET_TIMEOUT = 10
from typing import TypeVar
import numpy
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.cluster import KMeans
Self = TypeVar("Self", bound="HierarchicalKmeans")
class HierarchicalKmeans(BaseEstimator, ClusterMixin):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@altescy
altescy / selector.py
Created August 11, 2022 09:43
Example of interactive selector in Python
from __future__ import annotations
import os
import shutil
import subprocess
class Selector:
SUPPORTED_SELECTOR_COMMANDS = {"fzf", "peco"}
ENVKEY_SELECTOR_COMMAND = "SELECTOR_COMMAND"
from typing import Optional, cast
import torch
class MAB(torch.nn.Module):
def __init__(
self,
input_dim: int,
num_heads: int,