Skip to content

Instantly share code, notes, and snippets.

View AlexMikhalev's full-sized avatar

Dr Alexander Mikhalev AlexMikhalev

View GitHub Profile
@AlexMikhalev
AlexMikhalev / export_trace.py
Created March 18, 2021 22:53 — forked from lantiga/export_trace.py
🤗 Huggingface Bert on RedisAI
from transformers import BertForQuestionAnswering
import torch
bert_name = "bert-large-uncased-whole-word-masking-finetuned-squad"
model = BertForQuestionAnswering.from_pretrained(bert_name, torchscript=True)
model.eval()
inputs = [torch.ones(1, 2, dtype=torch.int64),
torch.ones(1, 2, dtype=torch.int64),
@AlexMikhalev
AlexMikhalev / RedisGears5.py
Created February 11, 2021 12:14
RedisGears5.py
bg = GearsBuilder('KeysReader')
bg.foreach(process_item)
bg.count()
bg.register('sentence:*', mode="async_local",onRegistered=OnRegisteredAutomata)
@AlexMikhalev
AlexMikhalev / RedisGears4.py
Created February 11, 2021 12:13
RedisGears4.py
import httpimport
with httpimport.remote_repo(['stop_words'], "https://raw.githubusercontent.com/explosion/spaCy/master/spacy/lang/en/"):
import stop_words
from stop_words import STOP_WORDS
@AlexMikhalev
AlexMikhalev / RedisGears3.py
Created February 11, 2021 12:08
RedisGears3.py
global sym_spell
if not sym_spell:
sym_spell=load_symspell()
suggestions = sym_spell.lookup_compound(sentence['value'], max_edit_distance=1,
transfer_casing=True, ignore_non_words=True)
@AlexMikhalev
AlexMikhalev / RedisGears2.py
Last active February 11, 2021 12:08
RedisGears2.py
"""
load symspell and relevant dictionaries
"""
sym_spell=None
def load_symspell():
import pkg_resources
from symspellpy import SymSpell, Verbosity
sym_spell = SymSpell(max_dictionary_edit_distance=1, prefix_length=7)
dictionary_path = pkg_resources.resource_filename(
@AlexMikhalev
AlexMikhalev / Gears1.py
Created February 11, 2021 12:07
RedisGears.py
gb = GB('KeysReader')
gb.filter(filter_language)
gb.flatmap(parse_paragraphs)
gb.map(spellcheck_sentences)
gb.foreach(save_sentences)
gb.count()
gb.register('paragraphs:*',keyTypes=['string','hash'], mode="async_local")
@AlexMikhalev
AlexMikhalev / rgcluster.bash
Created February 11, 2021 12:05
docker compose Redis Gears cluster
docker exec -it rgcluster /cluster/create-cluster call RG.CONFIGSET ExecutionMaxIdleTime 300000
docker exec -it rgcluster /cluster/create-cluster call CONFIG SET proto-max-bulk-len 2048mb
docker exec -it rgcluster /cluster/create-cluster call CONFIG SET list-compress-depth 1
docker exec -it rgcluster /cluster/create-cluster call CONFIG SET cluster-node-timeout 30000
@AlexMikhalev
AlexMikhalev / umls_sample.py
Created February 11, 2021 12:05
UMLS scispacy
import scispacy
import spacy
from scispacy.abbreviation import AbbreviationDetector
from scispacy.umls_linking import UmlsEntityLinker
nlp = spacy.load("en_core_sci_sm")
#^^^ at this import you area looking at 9 GB RAM consumption
#even before processing starts
# Add the abbreviation pipe to the spacy pipeline.
@AlexMikhalev
AlexMikhalev / get-obsidian-posts.py
Created January 19, 2021 13:46
Sync notion to obsidian world md
from notion.client import NotionClient
import datetime
import os
from slugify import slugify
import re
import requests
import time
import hashlib
import shutil
import sys
@AlexMikhalev
AlexMikhalev / crash.txt
Created January 11, 2021 12:15
RedisGears Cluster Crash Bug report
=== REDIS BUG REPORT START: Cut & paste starting from here ===
13:S 11 Jan 2021 12:11:34.456 # === ASSERTION FAILED ===
13:S 11 Jan 2021 12:11:34.456 # ==> src/readers/keys_reader.c:228 'RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ARRAY' is not true
13:S 11 Jan 2021 12:11:34.456 # (forcing SIGSEGV to print the bug report.)
13:S 11 Jan 2021 12:11:34.456 # Redis 6.0.1 crashed by signal: 11
13:S 11 Jan 2021 12:11:34.456 # Crashed running the instruction at: 0x55b3cdb49d3b
13:S 11 Jan 2021 12:11:34.456 # Accessing address: 0xffffffffffffffff
13:S 11 Jan 2021 12:11:34.456 # Failed assertion: RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ARRAY (src/readers/keys_reader.c:228)
------ STACK TRACE ------