Posts

Showing posts with the label Colab

Solving [SSL: WRONG_SIGNATURE_TYPE] wrong signature type when Scraping Websites

So, recently I worked on a project where I was required to collect all available course information at a targeted university website. You know the drill. I started to import requests and BeautifulSoup and was about to pass the target URL into the requests.get(). I thought it was going to be smooth and easy as it used to be. Unfortunately, an error came up and prevented the scraping to be running.  This was the error: [SSL: WRONG_SIGNATURE_TYPE] wrong signature type So what I did (as always) was started surfing StackOverflow. Without taking much time, I found this post . Here's the workaround, just add the TLSAdapter class (as shown below) and you're good to go. So, instead of using requests.get() directly, it is suggested to make use of the session in order to incorporate the TLSAdapter() prior to reaching the target URL. Credit goes to pyOliv . Hope it helps you too.

Adding Months to Current Date? Use relativedelta()

Image
After minutes of surfing in the ocean of Stackoverflow, find this trick to add months to the current date (dealing with date is painful already in any language, at least to me personally). Use relativedelta() from dateutil library. and the result shows: Check out the date after adding two months. Voila! Just like that. Credit: https://stackoverflow.com/questions/4130922/how-to-increment-datetime-by-custom-months-in-python-without-using-library

Computing Loss in PyTorch

Image
How it works: How the implementation in PyTorch looks like:   Rule of thumb: The more accurate the network, the smaller the loss. reference: Datacamp's Introduction to Deep Learning with PyTorch

Using Softmax in Pytorch

Image
First thing, import torch and torch.nn In the next steps, define a random input tensor with the shape of (2,3). See the difference when softmax is applied on the dimension-0 (dim=0) and dimension-1 (dim=1). Hope this helps. reference:  https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html

Word Wrapping in Google Colab using textwrap

 import textwrap wrapper = textwrap.TextWrapper(width=40, initial_indent=" " * 4, subsequent_indent=" " * 4, break_long_words=False, break_on_hyphens=False) print( wrapper.fill (string)) source