Skip to content
Advertisement

Tag: pytorch

Can BERT output be fixed in shape, irrespective of string size?

I am confused about using huggingface BERT models and about how to make them yield a prediction at a fixed shape, regardless of input size (i.e., input string length). I tried to call the tokenizer with the parameters padding=True, truncation=True, max_length = 15, but the prediction output dimensions for inputs = [“a”, “a”*20, “a”*100, “abcede”*20000] are not fixed. What am

Why tensor size was not changed?

I made the toy CNN model. Then, I had checked model.summary via this code And I was able to get the following results: I want to reduce model size cuz i wanna increase the batch size. So, I had changed torch.float32 -> torch.float16 via NVIDIA/apex As a result, torch.dtype was changed torch.float16 from torch.float32. But, Param size (MB): 35.19 was

How to avoid two variables refering to the same data? #Pytorch

During initializing, I tried to reduce the repeats in my code, so instead of: I wrote: However, I find that the second method is wrong. If I assign the data to variables h,c, any change on h would also be applied to c results of the test above: Is there a more elegent way to initialize two indenpendent variables? Answer

Receiving Infinity Infinity in LineString

I am try get linestring so I can measure the distance and time. Here in this linestring I am getting nan distance and time. Also, pleased to hear any of your suggestion on my code or logic. Thanks data: Code: Output: Answer Probably, previous pyproj EPSG was switching the opposite interpretation. So I change the EPSG code with below:

How to test a trained model saved in .pth.tar files?

I am working with CORnet-Z and I am building a separate test file. The model seems to be saved as .pth.tar files What would be the best approach to load this model and run evaluation and testing? Answer To test a model you need to load the state dictionary of your trained model and optimizer (if applicable). But, if you

Is there a way to use torch.nn.DataParallel with CPU?

I’m trying to change some PyTorch code so that it can run on the CPU. The model was trained with torch.nn.DataParallel() so when I load the pre-trained model and try using it I must use nn.DataParallel() which I am currently doing like this: However after I switched my torch device to cpu like this: I got this error: I’m assuming

How to efficiently draw a plot of a torch.nn model?

I’m exploring neural networks, and I want to model some pictures with neural network. Picture is a function that maps pixel coordinates to color, so I make my network also with 2 input variables (x, y) and 1 (shade) to 3 (R, G, B) output coordinates. For example, like this: Now, I plot it like this: But it looks ugly

Whats the purpose of torch.positive?

From the documentation: torch.positive(input) → Tensor Returns input. Throws a runtime error if input is a bool tensor. It just returns the input and throws error if its a bool tensor, but that’s not an efficient nor readable way of checking if a tensor is bool. Answer It seems like pytorch added pytorch.positive in parity with numpy which has a

Advertisement