Skip to content

Instantly share code, notes, and snippets.

View zxh326's full-sized avatar
:bowtie:
Focusing

Zzde zxh326

:bowtie:
Focusing
View GitHub Profile
@zxh326
zxh326 / ohai.gif
Created October 16, 2023 16:04 — forked from Qix-/ohai.gif
ohaider
ohai.gif
@zxh326
zxh326 / semantic_search_with_gzip.py
Created July 16, 2023 06:02 — forked from kyo-takano/lexical_search_with_gzip.py
Semantic Search with gzip (gzipによるセマンティック検索)
import gzip
def gzip_search(query: str, candidate_chunks: list[str], top_k: int=1):
"""
文字列ベースで類似したテキストチャンクを推定するアルゴリズム.
`query`, `chunk`, および`query + " " + chunk`をそれぞれgzipで圧縮し、編集距離のようなものをベースに評価する.
Parameters:
query (str): 検索クエリとして使用する文字列.
top_k (int, optional): 返される類似チャンクの上位k個を指定する (default: 1).
@zxh326
zxh326 / b.sh
Created October 13, 2018 15:12
git alias
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@zxh326
zxh326 / share.py
Created June 24, 2018 15:20
[multiprocessing] share Value
# Demo 1
"""
The 'd' and 'i' arguments used when creating num and arr are typecodes of the kind used by the array module: 'd' indicates a double precision float and 'i' indicates a signed integer. These shared objects will be process and thread-safe.
For more flexibility in using shared memory one can use the multiprocessing.sharedctypes module which supports the creation of arbitrary ctypes objects allocated from shared memory.
"""
from multiprocessing import Process, Value, Array
def f(n, a):
n.value = 3.1415927