Skip to content

Commit

Permalink
Merge pull request #81 from georgian-io/akash/docs_update
Browse files Browse the repository at this point in the history
Documentation Update
  • Loading branch information
akashsara authored Sep 24, 2024
2 parents b2f05ee + 75f9a04 commit c39bd85
Show file tree
Hide file tree
Showing 40 changed files with 1,384 additions and 1,259 deletions.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/modules/data.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/modules/model.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c92f8b10e869a683d597b2d7c8e8def5
config: 971d289f0ed5f6229219678519118097
tags: 645f666f9bcd5a90fca523b33c5a78b7
2 changes: 1 addition & 1 deletion docs/build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../_static/doctools.js?v=888ff710"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
Expand Down
888 changes: 542 additions & 346 deletions docs/build/html/_modules/multimodal_transformers/data/load_data.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="../../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../../_static/doctools.js?v=888ff710"></script>
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
Expand Down Expand Up @@ -79,8 +79,12 @@
<div itemprop="articleBody">

<h1>Source code for multimodal_transformers.data.tabular_torch_dataset</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Union</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">import</span> <span class="nn">transformers</span>
<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">Dataset</span> <span class="k">as</span> <span class="n">TorchDataset</span>


Expand All @@ -91,31 +95,33 @@ <h1>Source code for multimodal_transformers.data.tabular_torch_dataset</h1><div
<span class="sd"> :obj:`TorchDataset` wrapper for text dataset with categorical features</span>
<span class="sd"> and numerical features</span>

<span class="sd"> Parameters:</span>
<span class="sd"> encodings (:class:`transformers.BatchEncoding`):</span>
<span class="sd"> The output from encode_plus() and batch_encode() methods (tokens, attention_masks, etc) of</span>
<span class="sd"> a transformers.PreTrainedTokenizer</span>
<span class="sd"> categorical_feats (:class:`numpy.ndarray`, of shape :obj:`(n_examples, categorical feat dim)`, `optional`, defaults to :obj:`None`):</span>
<span class="sd"> An array containing the preprocessed categorical features</span>
<span class="sd"> numerical_feats (:class:`numpy.ndarray`, of shape :obj:`(n_examples, numerical feat dim)`, `optional`, defaults to :obj:`None`):</span>
<span class="sd"> An array containing the preprocessed numerical features</span>
<span class="sd"> labels (:class: list` or `numpy.ndarray`, `optional`, defaults to :obj:`None`):</span>
<span class="sd"> The labels of the training examples</span>
<span class="sd"> df (:class:`pandas.DataFrame`, `optional`, defaults to :obj:`None`):</span>
<span class="sd"> Model configuration class with all the parameters of the model.</span>
<span class="sd"> This object must also have a tabular_config member variable that is a</span>
<span class="sd"> TabularConfig instance specifying the configs for TabularFeatCombiner</span>
<span class="sd"> :param encodings:</span>
<span class="sd"> The output from `encode_plus()` and `batch_encode()` methods (tokens, attention_masks, etc.) of a `transformers.PreTrainedTokenizer`.</span>

<span class="sd"> :param categorical_feats:</span>
<span class="sd"> An array containing the preprocessed categorical features. Shape: `(n_examples, categorical feat dim)`.</span>

<span class="sd"> :param numerical_feats:</span>
<span class="sd"> An array containing the preprocessed numerical features. Shape: `(n_examples, numerical feat dim)`.</span>

<span class="sd"> :param labels:</span>
<span class="sd"> The labels of the training examples.</span>

<span class="sd"> :param df:</span>
<span class="sd"> The original dataset. Optional and used only to save the original dataset with the preprocessed dataset.</span>

<span class="sd"> :param label_list:</span>
<span class="sd"> A list of class names for each unique class in labels.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">encodings</span><span class="p">,</span>
<span class="n">categorical_feats</span><span class="p">,</span>
<span class="n">numerical_feats</span><span class="p">,</span>
<span class="n">labels</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">df</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">label_list</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">encodings</span><span class="p">:</span> <span class="n">transformers</span><span class="o">.</span><span class="n">BatchEncoding</span><span class="p">,</span>
<span class="n">categorical_feats</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">],</span>
<span class="n">numerical_feats</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">],</span>
<span class="n">labels</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">df</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">label_list</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">df</span> <span class="o">=</span> <span class="n">df</span>
<span class="bp">self</span><span class="o">.</span><span class="n">encodings</span> <span class="o">=</span> <span class="n">encodings</span>
Expand All @@ -128,13 +134,13 @@ <h1>Source code for multimodal_transformers.data.tabular_torch_dataset</h1><div
<span class="k">else</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">labels</span><span class="p">)))]</span>
<span class="p">)</span>

<span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">item</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="n">val</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">encodings</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
<span class="n">item</span><span class="p">[</span><span class="s2">&quot;labels&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
<span class="p">)</span>
<span class="n">item</span><span class="p">[</span><span class="s2">&quot;cat_feats&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cat_feats</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span><span class="o">.</span><span class="n">float</span><span class="p">()</span>
<span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cat_feats</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span><span class="o">.</span><span class="n">float</span><span class="p">()</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cat_feats</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="k">else</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="p">)</span>
Expand All @@ -145,13 +151,13 @@ <h1>Source code for multimodal_transformers.data.tabular_torch_dataset</h1><div
<span class="p">)</span>
<span class="k">return</span> <span class="n">item</span>

<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">encodings</span><span class="p">[</span><span class="s2">&quot;input_ids&quot;</span><span class="p">])</span>

<div class="viewcode-block" id="TorchTabularTextDataset.get_labels">
<a class="viewcode-back" href="../../../modules/data.html#multimodal_transformers.data.TorchTabularTextDataset.get_labels">[docs]</a>
<span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;returns the label names for classification&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the label names for classification.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_list</span></div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="../../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../../_static/doctools.js?v=888ff710"></script>
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="../../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../../_static/doctools.js?v=888ff710"></script>
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="../../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../../_static/doctools.js?v=888ff710"></script>
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
Expand Down
Loading

0 comments on commit c39bd85

Please sign in to comment.