text
stringlengths
81
47k
source
stringlengths
59
147
Question: <p>I am trying to import AutoTokenizer and AutoModelWithLMHead, but I am getting the following error:</p> <p>ImportError: cannot import name 'AutoTokenizer' from partially initialized module 'transformers' (most likely due to a circular import)</p> <p>First, I install transformers: <code>pip install transform...
https://stackoverflow.com/questions/68481189/huggingface-autotokenizer-cannot-be-referenced-when-importing-transformers
Question: <p>I am trying to fine-tune a pretrained huggingface BERT model. I am importing the following</p> <pre><code>from transformers import (AutoTokenizer, AutoConfig, AutoModelForSequenceClassification, TrainingArguments, Trainer) </code></pre> <p>and get the following error:</p> <pre...
https://stackoverflow.com/questions/70066746/cannot-import-name-trainingarguments-from-transformers
Question: <p>There is a lot of talk about <code>Applicative</code> <em>not</em> needing its own transformer class, like this:</p> <pre><code>class AppTrans t where liftA :: Applicative f =&gt; f a -&gt; t f a </code></pre> <p>But I can define applicative transformers that don't seem to be compositions of applicat...
https://stackoverflow.com/questions/37761078/are-applicative-transformers-really-superfluous
Question: <p>I'm using Spacy-Transformers to build some NLP models.</p> <p>The <a href="https://spacy.io/universe/project/spacy-transformers#gatsby-noscript" rel="nofollow noreferrer">Spacy-Transformers docs</a> say:</p> <blockquote> <p><strong>spacy-transformers</strong></p> <p><em>spaCy pipelines for pretrained BERT,...
https://stackoverflow.com/questions/68946827/spacy-transformers-access-gpt-2
Question: <p>I am trying to import BloomTokenizer from transformers</p> <pre><code>from transformers import BloomTokenizer </code></pre> <p>and I receive the following error</p> <pre><code>Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; ImportError: cannot import name 'Blo...
https://stackoverflow.com/questions/73107703/issue-when-importing-bloomtokenizer-from-transformers-in-python
Question: <p>I'm trying to use huggingface transformers. (Win 11, Python 3.9, jupyternotebook, virtual environment)</p> <p>When I ran code:</p> <pre><code>from transformers import pipeline print(pipeline('sentiment-analysis')('I hate you')) </code></pre> <p>I got an error :</p> <blockquote> <p>FileNotFoundError: [WinEr...
https://stackoverflow.com/questions/73594934/huggingface-transformers-cache-directory
Question: <p>TypeScript has several high-level APIs to implement <strong>watch/compile,</strong> for example:</p> <ul> <li><a href="https://github.com/microsoft/TypeScript/blob/0b38a9a2b03d3c651822bc2a20d381545384f0f5/src/compiler/watchPublic.ts#L196" rel="nofollow noreferrer"><b>createWatchCompilerHost</b>( rootFile...
https://stackoverflow.com/questions/62026189/typescript-custom-transformers-with-ts-createwatchprogram
Question: <p>Here is my custom transformer, meant to transform the subject dataframe of encoding and scaling:</p> <pre><code>class DfGrooming(BaseEstimator, TransformerMixin): def __init__(self): self.encodable_columns = ['Education','EmploymentType','MaritalStatus', 'HasMortgage', 'HasDependents', 'LoanPur...
https://stackoverflow.com/questions/77570948/including-multiple-dataset-transformers-in-custom-transformer
Question: <p>As a math student, the first thing I did when I learned about monads in Haskell was check that they really were monads in the sense I knew about. But then I learned about monad transformers and those don't quite seem to be something studied in category theory.</p> <p>In particular I would expect them to b...
https://stackoverflow.com/questions/6854303/what-are-haskells-monad-transformers-in-categorical-terms
Question: <p>I was just looking into monad transformers in real world Haskell. The book said that to make something a monad transformer, you need to make it an instance of the MonadTrans type class.</p> <p>So the book defined a new Transformer, the <code>MaybeT m a</code> transformer.</p> <p>They defined the monadTra...
https://stackoverflow.com/questions/39638546/monad-transformers-lift
Question: <p>I've found myself writing a lot of transformers to generify some stream operations such as retry, apply schedulers, etc. Which made me write a lot of code duplication because each stream type(single, completable, etc.) has it's own Transformer so I had to implement 4 different transformers which do exactly...
https://stackoverflow.com/questions/54901081/rxjava-how-to-generify-transformers
Question: <p>I basically just want to use the transformers pipeline() to classify data, but independent of which model I try to use, it returns the same error, stating <strong>Numpy is not available</strong></p> <p>Code I'm running:</p> <pre><code>pipe = pipeline(&quot;text-classification&quot;, model=&quot;AdamLucek/r...
https://stackoverflow.com/questions/78863932/runtimeerror-numpy-is-not-available-transformers
Question: <p>I am trying to import ConditionalGeneration from transformers in jupyter notebook</p> <pre><code>from transformers import ConditionalGeneration </code></pre> <p>but encounter following error.I install different version and different method for installing pytorch and transformers but I can't solve it.</p> <...
https://stackoverflow.com/questions/74101343/issue-when-import-conditionalgeneration-from-transformers-in-python
Question: <p>I tried on a notebook to install the package transformers, it failed:</p> <p><code>!pip install transformers</code></p> <p>I get this:</p> <pre><code>FULLTRACE: Collecting transformers Obtaining dependency information for transformers from https://files.pythonhosted.org/packages/12/dd/f17b11a93a9ca27728e...
https://stackoverflow.com/questions/77519523/missing-convert-trajectory-transformer-original-pytorch-checkpoint-to-pytorch-py
Question: <p>After installing Transformers using</p> <pre><code>pip install Transformers </code></pre> <p>I get version 4.25.1 , but when I try to import Transformer by</p> <pre><code>from tensorflow.keras.layers import Transformer # or from tensorflow.keras.layers.experimental import Transformer </code></pre> <p>I ge...
https://stackoverflow.com/questions/74914230/how-to-import-transformers-with-tensorflow
Question: <p>I'm trying to get one to many relationship objects with transformers. I want to get include metas but i only get just regular transform fields.</p> <p>my transformer:</p> <pre><code>class AssistantTransformer extends TransformerAbstract { protected $availableIncludes = [ 'assistantmetas' ...
https://stackoverflow.com/questions/44900145/laravel-dingo-nested-transformers
Question: <p>The default cache directory lacks disk capacity, I need to change the configuration of the default cache directory. How can I do that?</p> Answer: <p>You can specify the cache directory whenever you load a model with <a href="https://huggingface.co/transformers/main_classes/model.html#transformers.PreTrai...
https://stackoverflow.com/questions/63312859/how-to-change-huggingface-transformers-default-cache-directory
Question: <p>The wiki on www.haskell.org tells us the following about Applicative Transformers:</p> <blockquote> <p>So where are applicative transformers? The answer is, that we do not need special transformers for applicative functors since they can be combined in a generic way. <a href="http://www.haskell.org/h...
https://stackoverflow.com/questions/12587195/examples-of-haskell-applicative-transformers
Question: <p>I'm instantiating a CodeBert Model using AutoModel.fromPretrained.</p> <pre><code>File &quot;/public.hpc/codeBertConcat/./codeBertConcatEvaluation.py&quot;, line 278, in &lt;module&gt; model = CodeBERTConcatenatedClass(num_classes=NUM_CLASSES).to(DEVICE) File &quot;/public.hpc/codeBertConcat/./codeBe...
https://stackoverflow.com/questions/78566180/transformers-automodel-from-pretrained-istantiation-error
Question: <p>I would like to use transformers in my Python code from NodeJs but it is not working without showing any error. Just by importing transformers my code isn't working. Of course by removing that part, the code runs smoothly.</p> <p>NodeJs code</p> <pre><code>const spawn = require(&quot;child_process&quot;).s...
https://stackoverflow.com/questions/73549859/how-to-use-transformers-from-nodejs-script
Question: <p>I am trying to use the huggingface transformers library in a hosted Jupyter notebook platform called Deepnote. I want to download a model through the pipeline class but unfortunately deepnote does not support IPyWidgets. Is there a way to disable IPywidgets when using transformers? Specifically the below c...
https://stackoverflow.com/questions/66644432/use-huggingface-transformers-without-ipywidgets
Question: <p>I have this code:</p> <pre><code>from flask import Flask, request, jsonify from flask_cors import CORS from transformers import pipeline app = Flask(__name__) CORS(app) model = pipeline(&quot;text-generation&quot;, model=&quot;MBZUAI-Paris/Atlas-Chat-9B&quot;) @app.route('/generate', methods=['POST']) de...
https://stackoverflow.com/questions/79130386/python-transformers-cant-load
Question: <p>I am running this code:</p> <p>I have these updated packages versions: tqdm-4.65.0 transformers-4.27.4</p> <p>I am running this code: from transformers import AutoTokenizer, AutoModel</p> <p>I am obtaining this erros: ImportError: cannot import name 'ObjectWrapper' from 'tqdm.utils' (/Users/anitasancho/opt...
https://stackoverflow.com/questions/75991822/from-transformers-import-autotokenizer-automodel
Question: <p>I'm trying to install the transformers library on HPC. I do:</p> <pre><code>git clone https://github.com/huggingface/transformers.git cd transformers pip install -e . --user </code></pre> <p>All three of these work as expected, with the last output being:</p> <pre><code>Successfully installed dataclasses-0...
https://stackoverflow.com/questions/62995253/installing-transformers-on-hpc-cluster
Question: <p>I have been getting this error message for days on different projects and still can't understand where its from. This seems to only happen when I use tensorflow and transformers together. Can't really find anything for this specific error so help would be greatly appreciated. Am pretty new to this stuff.</...
https://stackoverflow.com/questions/78954987/consistent-error-message-when-using-transformers
Question: <p>I have been using transformers fine up until today. However, when I imported the package today, I received this error message:</p> <pre><code>In Transformers v4.0.0, the default path to cache downloaded models changed from '~/.cache/torch/transformers' to '~/.cache/huggingface/transformers'. Since you don'...
https://stackoverflow.com/questions/65383059/unable-to-import-hugging-face-transformers
Question: <p>In many cases, it isn't clear to me what is to be gained by combining two monads with a transformer rather than using two separate monads. Obviously, using two separate monads is a hassle and can involve do notation inside do notation, but are there cases where it just isn't expressive enough?</p> <p>One ...
https://stackoverflow.com/questions/38710154/why-are-monad-transformers-different-to-stacking-monads
Question: <p>I am trying to understand why transformers use multiple attention heads. I found the following <a href="https://towardsdatascience.com/simple-explanation-of-transformers-in-nlp-da1adfc5d64f" rel="noreferrer">quote</a>:</p> <blockquote> <p>Instead of using a single attention function where the attention can...
https://stackoverflow.com/questions/66244123/why-use-multi-headed-attention-in-transformers
Question: <p>I am trying to convert the following code to work with Transformers 2.5.0. As written, it works in version 4.18.0, but not 2.5.0.</p> <pre><code># Converting pretrained BERT classification model to regression model # i.e. extracting base model and swapping out heads from transformers import BertTokenizer,...
https://stackoverflow.com/questions/73127139/equivalent-to-tokenizer-in-transformers-2-5-0
Question: <p>I am unable to do: pip install -U sentence-transformers. I get this message on Anaconda Prompt: ERROR: Could not find a version that satisfies the requirement torch>=1.0.1 (from sentence-transformers) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2) ERROR: No matching distribution found for torch>=1.0.1 (f...
https://stackoverflow.com/questions/61994001/unable-to-pip-install-u-sentence-transformers
Question: <p>I'm trying to understand how to use Monad Transformers. I read the <a href="https://en.wikibooks.org/wiki/Haskell/Monad_transformers" rel="noreferrer">wiki article</a> about it and still have some questions.</p> <p>We have <code>IO</code> monad that needs to read input from user. But the input is not alwa...
https://stackoverflow.com/questions/44868593/understanding-monad-transformers-in-scala
Question: <p>Is there an elegant way to nest transformers for relationship use? I'm looking to build a REST interface that allows for collections to conditionally include relationship models. So far I've been marginally successful, but it seems to break down a bit when it comes to the transformers (I'll admit I'm a b...
https://stackoverflow.com/questions/31507673/laravel-5-1-dingo-nested-transformers
Question: <p>I created a virtual environment from the environment.yml file, and all packages were installed successfully except for the 'transformers' package. The requirement is to install 'transformers==4.18.0.dev0', but when I run the command:</p> <blockquote> <p><code>$pip install transformers==4.18.0.dev0</code></...
https://stackoverflow.com/questions/77897628/issue-installing-transformers-4-18-0-dev0-from-environment-yml-file
Question: <p>When POSTing to an endpoint in a service layer to update a user's profile, I need to strip certain values from the request payload (the profile with the desired modifications from the client) and re-attach them in the response payload (the updated profile from the server). I am currently performing behavi...
https://stackoverflow.com/questions/26387868/proper-use-of-transformers-vs-interceptors
Question: <p>I'm having a bit of difficulty with monad transformers at the moment. I'm defining a few different non-deterministic relations which make use of transformers. Unfortunately, I'm having trouble understanding how to translate cleanly from one effectful model to another.</p> <p>Suppose these relations are ...
https://stackoverflow.com/questions/16552316/transformation-under-transformers
Question: <p>Consider the <code>State</code> type - or at least a simplified version:</p> <pre><code>newtype State s a = State { runState :: s -&gt; (a, s) } </code></pre> <p>Now, let's say we want to derive the <code>StateT</code> monad transformer. <code>transformers</code> defines it as follows:</p> <pre><code>ne...
https://stackoverflow.com/questions/49587122/type-variable-location-in-transformers
Question: <p>I cloned this repository/documentation <a href="https://huggingface.co/EleutherAI/gpt-neo-125M" rel="nofollow noreferrer">https://huggingface.co/EleutherAI/gpt-neo-125M</a></p> <p>I get the below error whether I run it on google collab or locally. I also installed transformers using this</p> <pre><code>pip...
https://stackoverflow.com/questions/68604289/attributeerror-module-transformers-has-no-attribute-tfgptneoforcausallm
Question: <p>Can there be mtl-like mechanism for monad transformers created by FreeT / ProgramT ?</p> <p>My understanding of the history is as follows. Once upon a time monad transformer was invented. Then people started to stack monad transformers one on other, then found it annoying to insert <code>lift</code> every...
https://stackoverflow.com/questions/17936900/monad-stack-penetration-classes-with-free-operational-monad-transformers
Question: <p>I'm trying to roll my own compiler for Typescript due to the fact that I need to use transformers.</p> <p>We use ts-node to run some files (individual tests, etc.) and I also need the transformers to get passed in to the ts-node compiler.</p> <p>Here's my code</p> <pre><code>const ts = require('typescri...
https://stackoverflow.com/questions/57342857/how-to-pass-in-transformers-to-ts-node
Question: <p>I want to add <strong>Column transformers (read and write)</strong> <a href="https://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-column-read-and-write" rel="nofollow">like this:</a> to a Groovy domain class in a Grails application</p> Answer: <p>Depending on what you are tr...
https://stackoverflow.com/questions/20430940/grails-column-transformers-like-hibernate
Question: <p>I am confused about where <code>m</code> should be placed on the right side of the Monad transformers?</p> <p>For example:</p> <p><code>WriterT</code> is defined as</p> <pre><code>newtype WriterT w m a = WriterT { runWriterT :: m (a, w) } </code></pre> <p>while <code>ReaderT</code> is defined as</p> <...
https://stackoverflow.com/questions/51864209/confused-about-haskell-monad-transformers
Question: <p>I had my langchain project working on my win10 laptop, but after moving it to Debian GNU/Linux 12 server, I've learned that I can't install sentence transformers (python 3.11) in realation to problems with installing torch.</p> <p>Is there some alternative to SentenceTransformerEmbeddings without sentence...
https://stackoverflow.com/questions/78613151/sentencetransformerembeddings-without-installing-sentence-transformers
Question: <p>In my env(colab) I need the following library. Here is the list :</p> <pre><code>!pip install --quiet transformers==4.1.1 !pip install --quiet pytorch-lightning==1.1.3 #!pip install pytorch-lightning !pip install --quiet tokenizers==0.9.4 !pip install --quiet sentencepiece==0.1.94 !pip install torchtext==0...
https://stackoverflow.com/questions/69649310/importerror-cannot-import-name-bigbirdtokenizer-from-transformers-usr-loc
Question: <p>I have used the transformers function to download the whole model into local directory: /home/marcus/Desktop/project/OCR_transformer_practices/models/moondream2 by the following code:</p> <pre><code>from huggingface_hub import snapshot_download # Specify the model ID and revision model_id = &quot;vikhyatk...
https://stackoverflow.com/questions/79169173/fail-to-use-transformers-to-load-model-locally
Question: <p>I'm trying to do a simple text classification project with Transformers, I want to use the pipeline feature added in the V2.3, but there is little to no documentation.</p> <pre><code>data = pd.read_csv("data.csv") FLAUBERT_NAME = "flaubert-base-cased" encoder = LabelEncoder() target = encoder.fit_transfo...
https://stackoverflow.com/questions/60209265/how-to-use-the-huggingface-transformers-pipelines
Question: <p>I have an issue. I'm using Python 3.11 and I have the latest version of transformers 4.36.2</p> <p>The issue is that when I'm importing the pipeline module I facing the following issue in Jupyter Notebook:</p> <pre><code>RuntimeError: Failed to import transformers.pipelines because of the following error (...
https://stackoverflow.com/questions/77814471/unable-to-user-pipeline-module-inside-transformers-library
Question: <p>I am not able to import <strong>LLaMATokenizer</strong></p> <p>Any solution for this problem?</p> <p>I am using the code of this repo. <a href="https://github.com/zphang/transformers/tree/llama_push" rel="noreferrer">https://github.com/zphang/transformers/tree/llama_push</a> and trying to load the models a...
https://stackoverflow.com/questions/75907910/importerror-cannot-import-name-llamatokenizer-from-transformers
Question: <p>I have a simple transformers script looking like this.</p> <pre><code>from simpletransformers.seq2seq import Seq2SeqModel, Seq2SeqArgs args = Seq2SeqArgs() args.num_train_epoch=5 model = Seq2SeqModel( &quot;roberta&quot;, &quot;roberta-base&quot;, &quot;bert-base-cased&quot;, ) import pandas as...
https://stackoverflow.com/questions/71200243/simple-transformers-producing-nothing
Question: <p>I would like to use SuperGLUE tasks with huggingface-transformers. Looking at this page:</p> <p><a href="https://github.com/huggingface/transformers/blob/master/examples/README.md" rel="nofollow noreferrer">https://github.com/huggingface/transformers/blob/master/examples/README.md</a></p> <p>The only use...
https://stackoverflow.com/questions/61043681/how-to-use-superglue-with-huggingface-transformers
Question: <p>I want to write a custom transpiler using the typescript transformer api that outputs typescript instead of javascript. To accomplish this I would need to disable the default transformers (typescript → ecma2017 → ecma2016 → ...).</p> <p>Is this possible? I would prefer to use <code>tsc</code> directly, bu...
https://stackoverflow.com/questions/55514236/disable-default-typescript-transformers
Question: <p>I have been trying simple Monad Transformers where I have for comprehensions involving <code>M[F[A]]</code> where <code>M</code> and <code>F</code> are monads. How can I make <code>M[F[A]]</code> and <code>M[S[A]]</code> work together in a for comp if <code>S</code> is a different monad? </p> <p>For examp...
https://stackoverflow.com/questions/40503324/monad-transformers-in-scala
Question: <p>Get the following error while installing sentence-transformers on Windows 11 (using the latest version of Python and pip). Can someone please help with this? Checked many other similar posts, but none of those solutions work.</p> <pre><code>C:\Users\abc\ai\llama\jupyterproj\stlit&gt;py -m pip install sente...
https://stackoverflow.com/questions/78001556/error-while-installing-sentence-transformers
Question: <p>I am working on using monad transformers in C#.<br> I would like to know if the following code I present, shows that I have understood this.<br> I am fairly new to this so any feedback / comments are really welcome.<br> This example is just for wrapping a maybe monad in a validation monad.</p> <pre><code>...
https://stackoverflow.com/questions/20353256/monad-transformers-in-c
Question: <p>I have downloaded this <a href="https://huggingface.co/TheBloke/vicuna-13B-1.1-GPTQ-4bit-128g" rel="nofollow noreferrer">model</a> from huggingface. I am trying to load this model in transformers so I can do inferencing:</p> <pre><code>from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer...
https://stackoverflow.com/questions/76247802/loading-a-safetensor-file-in-transformers
Question: <p>I'm familiar with monads, e.g. <code>Reader</code>, <code>Error</code>, and <code>State</code>. Transformers, however, are very new to me, hence this question.</p> <p>Intuitively, I can tell there is a difference between the following two monad transformers, but I can't quite pinpoint what it is...</p> <...
https://stackoverflow.com/questions/36671136/what-is-difference-between-those-two-monad-transformers
Question: <p>I would like to use Huggingface Transformers to implement a chatbot. Currently, I have the code shown below. The transformer model already takes into account the history of past user input.</p> <p>Is there something else (additional code) I have to take into account for building the chatbot?</p> <p>Second,...
https://stackoverflow.com/questions/70055966/chatbot-using-huggingface-transformers
Question: <p>I am looking for a help building a data preprocessing pipleline using sklearn's ColumnTransformer functions.</p> <p>Currently my pipleline looks something like this:</p> <pre><code>from scipy.stats.mstats import winsorize from sklearn.compose import ColumnTransformer from sklearn.impute import SimpleImpu...
https://stackoverflow.com/questions/63475704/sklearn-columntransformer-duplicate-columns-in-transformers
Question: <p>I am using some transformers of Pyspark such as StringIndexer, StandardScaler and more. I first apply those to the training set and then later on I want to use the same transformation objects (same parameters of StringIndexerModel, StandardScalerModel) in order to apply them on the test set. Therefore, I a...
https://stackoverflow.com/questions/36136662/pyspark-save-transformers
Question: <p>I am working on a project for text classification using BERT</p> <p>I am getting ca. 90% accuracy by using simple transformers. But I only get like 60% using my own training for-loop (not published here) or using the trainer module from the transformers library. Both are done with the default parameters of...
https://stackoverflow.com/questions/64595546/higher-accuracy-using-simpletransformers-vs-transformers-library-with-bert
Question: <p>I am pretty new to Hugging-Face transformers. I am facing the following issue when I try to load <strong>xlm-roberta-base</strong> model from a given path:</p> <pre><code>&gt;&gt; tokenizer = AutoTokenizer.from_pretrained(model_path) &gt;&gt; Traceback (most recent call last): File &quot;&lt;stdin&gt;&qu...
https://stackoverflow.com/questions/62641972/hugging-face-transformers-loading-model-from-path-error
Question: <p>"Monads allow the programmer to build up computations using sequential building blocks" therefore it allows us to combine some computations. If this is the case, then why the following code can not be run? </p> <pre><code>import Control.Monad.Trans.State gt :: State String String gt = do name &lt;- ge...
https://stackoverflow.com/questions/45082178/monad-vs-monad-transformers
Question: <p>Why isn't it necessary to use lift for executing a function in an internal monad transformer environment, except for IO? I mean, if I have StateT over WriterT and WriterT over ReaderT, why can I do this?</p> <pre><code>tell $ {- any code here for the Writer -} foo &lt;- asks {- This for the reader -} and ...
https://stackoverflow.com/questions/17204573/monad-transformers-and-lift-function
Question: <p>I am currently fine-tuning a BERT model on a sequence classification task. To do this, I am using the transformers framework. This requires a Batch input in a Trainer: <a href="https://huggingface.co/transformers/_modules/transformers/trainer.html" rel="nofollow noreferrer">https://huggingface.co/transform...
https://stackoverflow.com/questions/64805769/fine-tuning-bert-on-sequenceclassification-using-transformers-framework
Question: <p>I keep getting this error when I try to use hugging face transformers library.</p> <pre><code>huggingface_hub.utils._validators.HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': 'C:/Users/FZH91R/PycharmProjects/DudeWheresMyHealing/Pytorch/tf_model.h5'. Use `repo_type` arg...
https://stackoverflow.com/questions/76900349/repo-id-error-when-using-hugging-face-transformers
Question: <p>I'm having a hard time understanding monad transformers, partly because most examples and explanations use Haskell.</p> <p>Could anyone give an example of creating a transformer to merge a Future and an Either monad in Javascript and how it can be used.</p> <p>If you can use the <code>ramda-fantasy</code...
https://stackoverflow.com/questions/42783479/monad-transformers-explained-in-javascript
Question: <p>The libraries used<br /> python : 3.7.16<br /> transformers : 4.24.0<br /> tensorflow : 2.4.1</p> <p>I am triyng to convert tensorflow wav2vec model into tflite in colab</p> <p><code>from transformers import Wav2Vec2Processor</code> for this line it gives a error cannot load the wav2vec2Processor. <code>fr...
https://stackoverflow.com/questions/76753228/cannot-import-from-transformers-import-wav2vec2processor
Question: <p>How do I check if PyTorch is using the GPU? The <code>nvidia-smi</code> command can detect GPU activity, but I want to check it directly from inside a Python script.</p> Answer: <p>These functions should help:</p> <pre><code>&gt;&gt;&gt; import torch &gt;&gt;&gt; torch.cuda.is_available() True &gt;&gt;&...
https://stackoverflow.com/questions/48152674/how-do-i-check-if-pytorch-is-using-the-gpu
Question: <p>How do I save a trained model in PyTorch? I have read that:</p> <ol> <li><a href="https://github.com/torch/torch7/blob/master/doc/serialization.md#torchsavefilename-object--format-referenced" rel="noreferrer"><code>torch.save()</code></a>/<a href="https://github.com/torch/torch7/blob/master/doc/serializati...
https://stackoverflow.com/questions/42703500/how-do-i-save-a-trained-model-in-pytorch
Question: <p>How do I print the summary of a model in PyTorch like what <code>model.summary()</code> does in Keras:</p> <pre><code>Model Summary: ____________________________________________________________________________________________________ Layer (type) Output Shape Param # Connec...
https://stackoverflow.com/questions/42480111/how-do-i-print-the-model-summary-in-pytorch
Question: <p>In numpy, we use <code>ndarray.reshape()</code> for reshaping an array.</p> <p>I noticed that in PyTorch, people use <code>torch.view()</code> for the same purpose, but at the same time, there is also a <code>torch.reshape()</code> existing.</p> <p>So I am wondering what the differences are between them an...
https://stackoverflow.com/questions/49643225/whats-the-difference-between-reshape-and-view-in-pytorch
Question: <p>I have a pytorch <code>Tensor</code> of shape <code>[4, 3, 966, 1296]</code>. I want to convert it to <code>numpy</code> array using the following code:</p> <pre><code>imgs = imgs.numpy()[:, ::-1, :, :] </code></pre> <p>How does that code work?</p> Answer: <p>There are 4 dimensions of the tensor you want ...
https://stackoverflow.com/questions/49768306/pytorch-tensor-to-numpy-array
Question: <p>What does <code>view()</code> do to the tensor <code>x</code>? What do negative values mean?</p> <pre><code>x = x.view(-1, 16 * 5 * 5) </code></pre> Answer: <p><code>view()</code> reshapes the tensor without copying memory, similar to numpy's <a href="https://docs.scipy.org/doc/numpy/reference/generated/n...
https://stackoverflow.com/questions/42479902/what-does-view-do-in-pytorch
Question: <p>How do I count the total number of parameters in a PyTorch model? Something similar to <code>model.count_params()</code> in Keras.</p> Answer: <p>PyTorch doesn't have a function to calculate the total number of parameters as Keras does, but it's possible to sum the number of elements for every parameter g...
https://stackoverflow.com/questions/49201236/check-the-total-number-of-parameters-in-a-pytorch-model
Question: <p>There seems to be several ways to create a copy of a tensor in PyTorch, including</p> <pre><code>y = tensor.new_tensor(x) #a y = x.clone().detach() #b y = torch.empty_like(x).copy_(x) #c y = torch.tensor(x) #d </code></pre> <p><code>b</code> is explicitly preferred over <code>a</code> and <code>d</code>...
https://stackoverflow.com/questions/55266154/pytorch-preferred-way-to-copy-a-tensor
Question: <p>Why does <a href="https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html" rel="noreferrer"><code>zero_grad()</code></a> need to be called during training?</p> <pre><code>| zero_grad(self) | Sets gradients of all model parameters to zero. </code></pre> Answer: <p>In <a href="h...
https://stackoverflow.com/questions/48001598/why-do-we-need-to-call-zero-grad-in-pytorch
Question: <p>How do I add L1/L2 regularization in PyTorch without manually computing it?</p> Answer: <p>See the <a href="http://pytorch.org/docs/optim.html#torch.optim.Adagrad" rel="noreferrer">documentation</a>. Add a <code>weight_decay</code> parameter to the optimizer for L2 regularization.</p>
https://stackoverflow.com/questions/42704283/l1-l2-regularization-in-pytorch
Question: <p>When should I use <code>.eval()</code>? I understand it is supposed to allow me to &quot;evaluate my model&quot;. How do I turn it back off for training?</p> <p>Example training <a href="https://github.com/natanielruiz/deep-head-pose/blob/master/code/train_hopenet.py" rel="noreferrer">code</a> using <code>...
https://stackoverflow.com/questions/60018578/what-does-model-eval-do-in-pytorch
Question: <p>I think it's a pretty common message for PyTorch users with low GPU memory:</p> <pre><code>RuntimeError: CUDA out of memory. Tried to allocate X MiB (GPU X; X GiB total capacity; X GiB already allocated; X MiB free; X cached) </code></pre> <p>I tried to process an image by loading each layer to GPU and the...
https://stackoverflow.com/questions/59129812/how-to-avoid-cuda-out-of-memory-in-pytorch
Question: <p>The <a href="https://pytorch.org/docs/stable/generated/torch.unsqueeze.html" rel="noreferrer">PyTorch documentation</a> says:</p> <blockquote> <p>Returns a new tensor with a dimension of size one inserted at the specified position. [...]</p> <pre><code>&gt;&gt;&gt; x = torch.tensor([1, 2, 3, 4]) &gt;&gt;&g...
https://stackoverflow.com/questions/57237352/what-does-unsqueeze-do-in-pytorch
Question: <p>I am reading through the documentation of PyTorch and found an example where they write </p> <pre><code>gradients = torch.FloatTensor([0.1, 1.0, 0.0001]) y.backward(gradients) print(x.grad) </code></pre> <p>where x was an initial variable, from which y was constructed (a 3-vector). The question is, what ...
https://stackoverflow.com/questions/43451125/pytorch-what-are-the-gradient-arguments
Question: <p>I am a little bit confused about the data augmentation performed in PyTorch. Now, as far as I know, when we are performing data augmentation, we are KEEPING our original dataset, and then adding other versions of it (Flipping, Cropping...etc). But that doesn't seem like happening in PyTorch. As far as I un...
https://stackoverflow.com/questions/51677788/data-augmentation-in-pytorch
Question: <pre><code>import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import torchvision.models as models import torchvision.datasets as dset import torchvision.transforms as transforms from torch.autograd import Variable from torchvision.models.vgg import model_urls from t...
https://stackoverflow.com/questions/52468956/how-do-i-visualize-a-net-in-pytorch
Question: <p>How do I initialize weights and biases of a network (via e.g. He or Xavier initialization)?</p> Answer: <h1>Single layer</h1> <p>To initialize the weights of a single layer, use a function from <a href="https://pytorch.org/docs/master/nn.init.html" rel="noreferrer"><code>torch.nn.init</code></a>. For inst...
https://stackoverflow.com/questions/49433936/how-do-i-initialize-weights-in-pytorch
Question: <p>What is the correct way to perform gradient clipping in pytorch?</p> <p>I have an exploding gradients problem.</p> Answer: <p><a href="https://pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_norm_.html#torch.nn.utils.clip_grad_norm_" rel="noreferrer"><code>clip_grad_norm</code></a> (which is ac...
https://stackoverflow.com/questions/54716377/how-to-do-gradient-clipping-in-pytorch
Question: <p>What does <code>x.contiguous()</code> do for a tensor <code>x</code>?</p> Answer: <p>There are a few operations on Tensors in PyTorch that do not change the contents of a tensor, but change the way the data is organized. These operations include:</p> <blockquote> <p><code>narrow()</code>, <code>view()</co...
https://stackoverflow.com/questions/48915810/what-does-contiguous-do-in-pytorch
Question: <p>How do I convert a PyTorch <code>Tensor</code> into a python <code>list</code>?</p> <p>I want to convert a tensor of size <code>[1, 2048, 1, 1]</code> into a list of 2048 elements. My tensor has floating point values. Is there a solution which also works with other data types such as int?</p> Answer: <p>U...
https://stackoverflow.com/questions/53903373/convert-pytorch-tensor-to-python-list
Question: <p>Does it call <code>forward()</code> in <code>nn.Module</code>? I thought when we call the model, <code>forward</code> method is being used. Why do we need to specify train()?</p> Answer: <p><code>model.train()</code> tells your model that you are training the model. This helps inform layers such as Dropou...
https://stackoverflow.com/questions/51433378/what-does-model-train-do-in-pytorch
Question: <p>On a Windows 10 PC with an NVidia GeForce 820M I installed CUDA 9.2 and cudnn 7.1 successfully, and then installed PyTorch using the instructions at pytorch.org:</p> <pre><code>pip install torch==1.4.0+cu92 torchvision==0.5.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html </code></pre> <p>But I...
https://stackoverflow.com/questions/60987997/why-torch-cuda-is-available-returns-false-even-after-installing-pytorch-with
Question: <p>With numpy, I can do a simple matrix multiplication like this:</p> <pre><code>a = numpy.ones((3, 2)) b = numpy.ones((2, 1)) result = a.dot(b) </code></pre> <p>However, this does not work with PyTorch:</p> <pre><code>a = torch.ones((3, 2)) b = torch.ones((2, 1)) result = torch.dot(a, b) </code></pre> <p>Thi...
https://stackoverflow.com/questions/44524901/how-to-multiply-matrices-in-pytorch
Question: <p>I want to reshape a vector of shape <code>(5,)</code> into a matrix of shape <code>(1, 5)</code>.</p> <p>With numpy, I can do:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; a = np.array([1, 2, 3, 4, 5]) &gt;&gt;&gt; a.shape (5,) &gt;&gt;&gt; a = np.reshape(a, (1, 5)) &gt;&gt;&gt; a.shape (1, ...
https://stackoverflow.com/questions/43328632/pytorch-reshape-tensor-dimension
Question: <p> Is there a Pytorch-internal procedure to detect <code>NaN</code>s in Tensors? Tensorflow has the <code>tf.is_nan</code> and the <code>tf.check_numerics</code> operations ... Does Pytorch have something similar, somewhere? I could not find something like this in the docs... </p> <p>I am looking specifical...
https://stackoverflow.com/questions/48158017/pytorch-operation-to-detect-nans
Question: <p>For several days now, I'm trying to replicate my keras training results with pytorch. Whatever I do, the pytorch model will overfit far earlier and stronger to the validation set then in keras. For pytorch I use the same XCeption Code from <a href="https://github.com/Cadene/pretrained-models.pytorch" rel="...
https://stackoverflow.com/questions/50079735/pytorch-vs-keras-pytorch-model-overfits-heavily
Question: <p>I want to do some timing comparisons between CPU &amp; GPU as well as some profiling and would like to know if there's a way to tell <a href="/questions/tagged/pytorch" class="post-tag" title="show questions tagged &#39;pytorch&#39;" rel="tag">pytorch</a> to not use the GPU and instead use the CPU only? I ...
https://stackoverflow.com/questions/53266350/how-to-tell-pytorch-to-not-use-the-gpu
Question: <p>I have been looking into deep learning frameworks lately and have been wondering about the origin of the name of PyTorch.</p> <p>With Keras, their <a href="https://keras.io/" rel="noreferrer">home page</a> nicely explains the name's origin, and with something like TensorFlow, the reasoning behind the name ...
https://stackoverflow.com/questions/51530778/why-is-pytorch-called-pytorch
Question: <p>Where is an explicit connection between the <code>optimizer</code> and the <code>loss</code>?</p> <p>How does the optimizer know where to get the gradients of the loss without a call liks this <code>optimizer.step(loss)</code>?</p> <p>-More context-</p> <p>When I minimize the loss, I didn't have to pass th...
https://stackoverflow.com/questions/53975717/pytorch-connection-between-loss-backward-and-optimizer-step
Question: <p>I'm familiar with how <a href="https://en.wikipedia.org/wiki/Einstein_notation" rel="noreferrer"><strong><code>einsum</code></strong></a> works in NumPy. A similar functionality is also offered by PyTorch: <a href="https://pytorch.org/docs/stable/torch.html#torch.einsum" rel="noreferrer"><strong>torch.eins...
https://stackoverflow.com/questions/55894693/understanding-pytorch-einsum
Question: <p>How do I train a simple neural network with PyTorch on a pandas dataframe <code>df</code>?</p> <p>The column <code>df[&quot;Target&quot;]</code> is the target (e.g. labels) of the network. This doesn't work:</p> <pre><code>import pandas as pd import torch.utils.data as data_utils target = pd.DataFrame(df[...
https://stackoverflow.com/questions/50307707/how-do-i-convert-a-pandas-dataframe-to-a-pytorch-tensor
Question: <p>Are these libraries fairly interchangeable?</p> <p>Looking here, <a href="https://stackshare.io/stackups/keras-vs-pytorch-vs-scikit-learn" rel="noreferrer">https://stackshare.io/stackups/keras-vs-pytorch-vs-scikit-learn</a>, it seems the major difference is the underlying framework (at least for PyTorch)....
https://stackoverflow.com/questions/54527439/differences-in-scikit-learn-keras-or-pytorch
Question: <p>I installed PyTorch with:</p> <pre><code>conda install pytorch torchvision cuda80 -c soumith </code></pre> <p>How do I uninstall and remove all PyTorch dependencies?</p> Answer: <p>From the <a href="https://conda.io/docs/commands/conda-uninstall.html" rel="noreferrer">anaconda docs</a>, you can uninstall ...
https://stackoverflow.com/questions/43664444/how-can-l-uninstall-pytorch-with-anaconda
Question: <p>I'm trying to have an in-depth understanding of how PyTorch Tensor memory model works.</p> <pre><code># input numpy array In [91]: arr = np.arange(10, dtype=float32).reshape(5, 2) # input tensors in two different ways In [92]: t1, t2 = torch.Tensor(arr), torch.from_numpy(arr) # their types In [93]: type...
https://stackoverflow.com/questions/48482787/pytorch-memory-model-torch-from-numpy-vs-torch-tensor