This file contains hidden or 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 re | |
from itertools import chain | |
def calculate_readability(code_string:str) -> float: | |
code = code_string.splitlines() | |
# Heuristic 1: Line length | |
max_line_length = 80 | |
long_lines = sum(1 for line in code if len(line) > max_line_length) |
This file contains hidden or 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
""" | |
generic & basic sbert-like embedder class for the jina-bert model | |
Usage: | |
model = EmbeddingModel("jinaai/jina-embeddings-v2-base-en") | |
embeddings = model.encode( | |
["How is the weather today?", "What is the current weather like today?"] | |
) | |
print(model.cos_sim(embeddings[0], embeddings[1])) |
This file contains hidden or 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 os | |
import argparse | |
import requests | |
from urllib.parse import urlparse | |
from tqdm import tqdm | |
from joblib import Parallel, delayed | |
from tenacity import retry, stop_after_attempt, wait_fixed | |
@retry(stop=stop_after_attempt(5), wait=wait_fixed(2)) |
This file contains hidden or 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 logging | |
import gzip | |
from pathlib import Path | |
import fire | |
from tqdm import tqdm | |
from tokenizers import ( | |
Tokenizer, | |
decoders, | |
models, | |
normalizers, |
This file contains hidden or 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 | |
# pip install nougat-ocr | |
# see https://github.com/facebookresearch/nougat for details and license | |
DEFAULT_BATCHSIZE=4 | |
usage() { | |
echo "Usage: $0 <path_to_directory> [--batchsize BATCHSIZE]" | |
exit 1 |
This file contains hidden or 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
# Example usage: | |
# python merge_peft.py --base_model=meta-llama/Llama-2-7b-hf --peft_model=./qlora-out --hub_id=alpaca-qlora | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
from peft import PeftModel | |
import torch | |
import argparse | |
def get_args(): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 | |
# install: sudo apt-get install inotify-tools | |
# Usage: ./scriptname.sh /path/to/monitor/directory /path/to/repo/directory | |
# If no monitor directory is passed, monitor directory = repo directory | |
# put & at the end of the command to run in background | |
# Define your monitor directory | |
MONITOR_DIR="${1:-$2}" | |
if [ -z "$MONITOR_DIR" ]; then |
This file contains hidden or 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
# coding=utf-8 | |
# Copyright 2023 The HuggingFace Inc. team. All rights reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
This file contains hidden or 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 logging | |
import warnings | |
from typing import List, Optional, Union | |
import numpy as np | |
import torch | |
from torch.nn import functional as F | |
from tqdm.auto import trange | |
from transformers import AutoTokenizer, PreTrainedModel, PreTrainedTokenizer, RwkvModel |