<jupyter_start><jupyter_text>Negative Sampling> Implementation of utilities for negative sampling.<jupyter_code>#hide
from nbdev.showdoc import *
from fastcore.nb_imports import *
from fastcore.test import *
#export
import random
#export
def random_neg_sample(item_set, item_size):
    item = random.randint(1, item_size - 1)
    while item in item_set:
        item = random.randint(1, item_size - 1)
    return item<jupyter_output><empty_output><jupyter_text>Tests<jupyter_code>item_set = [1,2,3,4,5]
item_size = 10
random.seed(32)
neg_item = random_neg_sample(item_set, item_size)

test_eq(neg_item, 8)
item_set = [1,2,3,4,5,5]
item_size = 10
random.seed(45)
neg_item = random_neg_sample(item_set, item_size)

test_eq(neg_item, 7)
item_set = [1,2,3,4,5]
item_size = -1
random.seed(45)

test_fail(lambda: random_neg_sample(item_set, item_size), contains="empty range for randrange() (1,-1, -2)")
#hide
%reload_ext watermark
%watermark -a "Sparsh A." -m -iv -u -t -d -p recohut<jupyter_output>PIL.Image 7.1.2
numpy     1.19.5
<NAME>. 
last updated: 2022-01-22 06:56:30 

recohut 0.0.11

compiler   : GCC 7.5.0
system     : Linux
release    : 5.4.144+
machine    : x86_64
processor  : x86_64
CPU cores  : 2
interpreter: 64bit
{'fraction_non_alphanumeric': 0.12326530612244897, 'fraction_numerical': 0.0653061224489796, 'mean_word_length': 4.755868544600939, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '78792', 'license': 'Apache-2.0', 'n_tokens_mistral': 544, 'n_tokens_neox': 502, 'n_words': 111, 'path': 'nbs/utils/utils.negative_sampling.ipynb', 'repo_name': 'sparsh-ai/recohut', 'size': '1227'}