o
    Ni!                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlm  mZ	 ddl
mZ dZdZdZG d	d
 d
ejjZG dd dejjZdS )zYelp Polarity Reviews dataset.    )absolute_import)division)print_functionNa  Large Yelp Review Dataset.
This is a dataset for binary sentiment classification. We provide a set of 560,000 highly polar yelp reviews for training, and 38,000 for testing. 
ORIGIN
The Yelp reviews dataset consists of reviews from Yelp. It is extracted
from the Yelp Dataset Challenge 2015 data. For more information, please
refer to http://www.yelp.com/dataset_challenge

The Yelp reviews polarity dataset is constructed by
Xiang Zhang (xiang.zhang@nyu.edu) from the above dataset.
It is first used as a text classification benchmark in the following paper:
Xiang Zhang, Junbo Zhao, Yann LeCun. Character-level Convolutional Networks
for Text Classification. Advances in Neural Information Processing Systems 28
(NIPS 2015).


DESCRIPTION

The Yelp reviews polarity dataset is constructed by considering stars 1 and 2
negative, and 3 and 4 positive. For each polarity 280,000 training samples and
19,000 testing samples are take randomly. In total there are 560,000 trainig
samples and 38,000 testing samples. Negative polarity is class 1,
and positive class 2.

The files train.csv and test.csv contain all the training samples as
comma-sparated values. There are 2 columns in them, corresponding to class
index (1 and 2) and review text. The review texts are escaped using double
quotes ("), and any internal double quote is escaped by 2 double quotes ("").
New lines are escaped by a backslash followed with an "n" character,
that is "
".
a]  @article{zhangCharacterlevelConvolutionalNetworks2015,
  archivePrefix = {arXiv},
  eprinttype = {arxiv},
  eprint = {1509.01626},
  primaryClass = {cs},
  title = {Character-Level {{Convolutional Networks}} for {{Text Classification}}},
  abstract = {This article offers an empirical exploration on the use of character-level convolutional networks (ConvNets) for text classification. We constructed several large-scale datasets to show that character-level convolutional networks could achieve state-of-the-art or competitive results. Comparisons are offered against traditional models such as bag of words, n-grams and their TFIDF variants, and deep learning models such as word-based ConvNets and recurrent neural networks.},
  journal = {arXiv:1509.01626 [cs]},
  author = {Zhang, Xiang and Zhao, Junbo and LeCun, Yann},
  month = sep,
  year = {2015},
}

zAhttps://s3.amazonaws.com/fast-ai-nlp/yelp_review_polarity_csv.tgzc                       s*   e Zd ZdZejjd fdd	Z  ZS )YelpPolarityReviewsConfigz&BuilderConfig for YelpPolarityReviews.Nc                    s,   t t| jdi | |ptjj | _dS )a"  BuilderConfig for YelpPolarityReviews.

    Args:
        text_encoder_config: `tfds.features.text.TextEncoderConfig`,
          configuration for the `tfds.features.text.TextEncoder` used for the
          Yelp `"text"` feature.
        **kwargs: keyword arguments forwarded to super.
    N )superr   __init__tfdsfeaturestextTextEncoderConfigtext_encoder_config)selfr   kwargs	__class__r   Z/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/text/yelp_polarity.pyr   S   s   
z"YelpPolarityReviewsConfig.__init__)N)	__name__
__module____qualname____doc__r	   coredisallow_positional_argsr   __classcell__r   r   r   r   r   P   s    r   c                   @   s   e Zd ZdZeddddedddejjjejj	 dd	ed
ddejjjejjj
ddd	edddejjjejjj
ddd	gZdd Zdd Zdd Zdd ZdS )YelpPolarityReviewszYelp Polarity reviews dataset.
plain_textz0.1.0z
Plain text)nameversiondescriptionbyteszGUses byte-level text encoding with `tfds.features.text.ByteTextEncoder`)encoder)r   r   r   r   
subwords8kz?Uses `tfds.features.text.SubwordTextEncoder` with 8k vocab sizei    )encoder_cls
vocab_sizesubwords32kz@Uses `tfds.features.text.SubwordTextEncoder` with 32k vocab sizei   c              	   C   sB   t jj| tt jt jj| jjdt jj	ddgddddt
dS )N)encoder_config12)namesr   labelzhttps://course.fast.ai/datasets)builderr   r
   supervised_keyshomepagecitation)r	   r   DatasetInfo_DESCRIPTIONr
   FeaturesDictTextbuilder_configr   
ClassLabel	_CITATION)r   r   r   r   _info   s   zYelpPolarityReviews._infoc                 c   s$    |  |D ]	\}}|d V  qd S )Nr   )_generate_examples)r   
train_file_exr   r   r   _vocab_text_gen   s   z#YelpPolarityReviews._vocab_text_genc                 C   sr   | t}tj|dd}tj|dd}| jjd | | t	j
jt	jjd|idt	j
jt	jjd|idgS )Nyelp_review_polarity_csvz	train.csvztest.csvr   filepath)r   
gen_kwargs)download_and_extract_DOWNLOAD_URLospathjoininfor
   maybe_build_from_corpusr;   r	   r   SplitGeneratorSplitTRAINTEST)r   
dl_manager	arch_pathr8   	test_filer   r   r   _split_generators   s"   

z%YelpPolarityReviews._split_generatorsc                 c   sh    t jj|"}t|D ]\}}||dd  |d dfV  qW d   dS 1 s-w   Y  dS )zGenerate Yelp examples.      r)   N)tfiogfileGFile	enumeratestrip)r   r=   fline_idliner   r   r   r7      s   ""z&YelpPolarityReviews._generate_examplesN)r   r   r   r   r   r	   r
   r   r   ByteTextEncoderSubwordTextEncoderBUILDER_CONFIGSr6   r;   rM   r7   r   r   r   r   r   b   sL    
	"r   )r   
__future__r   r   r   rA   tensorflow.compat.v2compatv2rQ   tensorflow_datasets.public_api
public_apir	   r0   r5   r@   r   BuilderConfigr   GeneratorBasedBuilderr   r   r   r   r   <module>   s   "