function code from the book "Natural Language Processing with Transformers" [duplicate] - python

This question already has answers here:
Why not python implicit line continuation on period?
(6 answers)
Closed 10 months ago.
I have never seen this repeated dot syntax, and I can't find any pointers to it anywhere.
Is it application of unsqueeze followed by expand followed by float() ?
input_mask_expanded = (attention_mask
.unsqueeze(-1)
.expand(token_embeddings.size())
.float())

It's equivalent to
input_mask_expanded = (attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float())
Just in a more readable form

Related

Explanation for string behavior ["somestring" "somestring"] being evaluated to ["somestringsomestring"] [duplicate]

This question already has answers here:
Python string literal concatenation
(1 answer)
String concatenation without '+' operator
(6 answers)
Closed 4 months ago.
I'm using python 3.10.4 right now.
I mistakenly wrote ["somestring" "somestring"] without a , separating the strings. Which evaluated to ["somestringsomestring"] without raising an error (which an error raised was my expectation).
And it seems like it was like that for previous versions.
How should I interpret the process of "string" "string" being evaluated to "stringstring"?

What is the Python ` symbol [duplicate]

This question already has answers here:
What do backticks mean to the Python interpreter? Example: `num`
(3 answers)
Meaning of the backtick character in Python
(2 answers)
Closed 1 year ago.
Lots of old python code I look in has this ` symbol around a lot of stuff, what does it do? Now it is not considered valid syntax, obviously.
And I don't think it is just another string identifier, its sometimes wrapped around functions in the code I'm looking at.
Any help will be appreciated.

Can someone please explain the logic behind using space in function call to an int value? [duplicate]

This question already has answers here:
Call methods of a number literal [duplicate]
(1 answer)
Accessing attributes on literals work on all types, but not `int`; why? [duplicate]
(4 answers)
Closed 1 year ago.
If I am doing this
>>> 5.bit_length()
I am getting SyntaxError: invalid syntax
but runs fine when using space
>>> 5 .bit_length()
Result -> 3
How does it reads the space ?

Replacing multiple strings in Python [duplicate]

This question already has answers here:
How to replace multiple substrings of a string?
(28 answers)
Closed 4 years ago.
I currently have the below Python code which works well:-
caseURL = r"\\mydomain\abc\lp_t\GB\123456\Original Format"
caseURL = caseURL.replace("lp_t", "lp_i")
caseURL = caseURL.replace("Original Format", "1")
This works fine as said and carries out the below conversion:-
\\mydomain\abc\lp_t\GB\123456\Original Format
\\mydomain\abc\lp_i\GB\123456\1\
This however just seems a bit clumsy. Is there a more pythonesque way to perform these two segment replacements?
Thanks
A similar post already exists:
How to replace multiple substrings of a string?
You can pick one answer from multiple options in the above post.

what's the meaning of "[ ]" in python references? [duplicate]

This question already has answers here:
What do square brackets, "[]", mean in function/class documentation?
(4 answers)
Closed 7 years ago.
I'm using python for a long time. but it was always strange to me why In python references, commands are written like this:
del var1[,var2[,var3[....,varN]]]]
I know that if I want to use the above command I should write it in this way:
del var1, var1
I can't understand the meaning of [] is it related to the lists? any help will be appreciated.
Its just showing that these parameters are optional. This is normal style for references.
There is nothing to do with this in python. Just a tutorial explanation.
I bealive, this is taken origin from Usage message

Categories

Resources