Why does the encoder output become key and value in transformer model - transformer-model

The deocoder of the transformer model(for machine translation) evaluates 2 kinds of attentions. First is the self attention while the second attention is evaluated between the target input and the encoder output. While calculating the second attention the encoder output is treated as key and value while the decoder output from the self attention of decoder is treated as query.
I have 2 questions:
What determines the choice of query and key in the second attention?
Generally, what should be chosen as query and key for different nlp
tasks?

Related

What type of stream does AVMediaType AVMEDIA_TYPE_NB represent

The FFmpeg AVMediaType enum contains AVMEDIA_TYPE_NB.
What type of data stream does this contain?
The name isn't very descriptive and the documentation doesn't describe it either.
Search results seem to indicate that it's used as a catch all value to remove packets. with a codec_type of AVMEDIA_TYPE_NB ever exist?
Constants in enums that end with _NB are used as the terminal member. They don't represent any entity. They are used as a loop terminator. NB = number

I need to unwrap/parse snmp results

Let me preface this with I know next to nothing about SNMP but I am learning. I am trying to get the device name from a printer.
I get the '1.3.6.1.2.1.1.5.0' OID. But it has a lot of additional information in it and I think it's some type of wrapper, but I don't know how to unwrap it.
Here are the results of my get
varBinds=[ObjectType(ObjectIdentity(ObjectName('1.3.6.1.2.1.1.5.0')), DisplayString(b'OFHP1', subtypeSpec=ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 65535)), ValueSizeConstraint(0, 255)), ValueSizeConstraint(0, 255))))]
the printer name is OFHP1. That's all I need. Is there a command to unwrap this, or do I need to just parse it by brute force?
When it comes to SNMP, you typically deal with so called variable-binding or OID-value pairs. That is conceptually similar to key-value pairs that you may encounter in other applications.
So your varBinds is a list of objects, each object represent a ket-value pair. To get the value you need to traverse that down to the component you need:
varBind = varBinds[0] # first var-bind
oid, value = varBind # unpack var-bind into OID and value
Now, values in SNMP are typed and constrained (they are actually ASN.1 types). That is why they are not just base Python types, but specialized objects. But you can strip extra information they carry and get a pure Python string (or int) from any SNMP scalar:
py_value = str(value) # turn SNMP value object into Python str
py_value = value.prettyPrint() # turn SNMP value object into a MIB-guided, human friendly representation

I wanted to develop a map reduce logic to find sentence count form the input file

I am new to hadoop and have basic idea of map reduce , the input to the map function will be key and value pair. So how do i basically identify when my sentence is completed and how can i count it. Is default input format that is TextInput format can be used or can we use some other input format to do it in a easier way.
I suppose you'd just check the line for periods. Decide whether an elipses (...) should be ignored, etc. Then as each line is passed to the map() method, you'd write out a key/value counting those legitimate periods to the context. The definition of what it means to end a sentence is your call. The logic to do that should be straightforward.
You can make it so that entire sentences are passed, one at a time, to the map() method, but that's much harder to do. You basically take that same logic and put it in a new input format type and corresponding RecordReader. If you have a choice go with the logic in the map() method and not the input format type and record reader.

Java applet - Real-time textfield input verification

I'm trying to develop an input real-time verification on a textfield in a Java applet.
The idea would be to have an input field that, if empty, once the user clicks in it it would show something like "0,00". Once the user starts to press the keys, only numbers should be accepted, and it would start to fill the text like this (imagine I input the numbers:
1,2,3,4,5,6):
"0,01" -> "0,12" -> "1,23" -> "12,34" -> "123,45" -> "1.234,56".
If the field is not empty the user can change the values but there will always be a "," dividing the decimal numbers.
I've been able to allow only numbers to be accepted but how can produce this kind of behavior? I know this may be a very specific question but any links or examples would be much appreciated. Thank you.
You will have to provide an input handler, that not only filters the input, but also calls a preset callback (made by you), that will update the required field in the way you want it to be updated.
You can use some functions, that can format numbers, given a specific format.
Basically, just keep a count on number of digits, already input, then parse it as a plain integer then multiply it by a power of 10, derived from the format, in your example would be something like 10 raised to the power of (numberOfInputDigits -2).

Have problems designing input and output for a calculator app

I am writing a button calculator. I have the code split into model, view and a controller. The model knows nothing about formatting, it is only concerned with numbers. All formatting is done in the view. The model gets its input as keypresses, each keypress is a part of an enum:
typedef enum {
kButtonUnknown = 0,
kButtonMemoryClear = 100,
kButtonMemoryPlus = 112,
kButtonMemoryMinus = 109,
kButtonMemoryRecall = 114,
kButtonClear = 99,
…
};
When the user presses a button (say 1), the model receives a button code (kButtonNum1), adds the corresponding number to a string input buffer ("1") and updates the numeric output value (1.0). The controller then passes the numeric output value to the view that formats it (1).
This is all plain, simple and clean, but does not really work. The problem is that when user enters a part of a number (say 0.00, going to enter 0.001), the input does not survive the way through model to view and the display says 0 instead of 0.00. I know why this happens ("0.00"::string parses to 0::double and that gets formatted as 0). What I don’t know is how to design the calculator so that the code stays clean and simple and the numbers will show up on screen exactly as the user types them.
I’ve already come with some kind of solution, but that’s essentially a hack and breaks the beautiful and simple flow from the calculator model to the display.
Ideas?
Current solution keeps track of the calculator state. If the calculator is building a number, I take the calculator input buffer (a string) and directly set the display contents (also a string). Otherwise I take the proper path, ie. take the numeric calculator output, pass it to the view as a double and the view uses its internal formatter to create a string for the display. Example input:
input | display | mode
------+---------+------------
0 | 0 | from string
0. | 0. | from string
0.0 | 0.0 | from string
0.0+ | 0 | from number
This is ugly. (1) The calculator has to expose its input buffer and state. (2) The view has to expose its display and allow setting its contents directly using a string. (3) I have to duplicate some of the formatting code to format the string I got from the calculator input buffer. If user enters 12345.000, I have to display 12,345.000 and therefore I’ve got to have a commification code for strings. Yuck.
On my calculator (HP48SX) the numbers in the display are formatted according to the settings for displaying numbers. Right now, if I enter 0.00 (or any variant thereof) it is displayed as 0.0000. Perhaps you could separate display (ie formatting) from internal number representation ? In terms of MVC I guess that this would be implemented as state in the C.
EDIT in response to OP's comment. I don't fully understand the limitations of what you call a button calculator so you're on your own there. As for separation, I would design the calculator such that:
Model is always working with whatever you use for representing numbers: floats, doubles, decimals, what-have-you.
View is always working with strings which present numbers nicely and allow users to enter as they wish.
Controller translates from string to number, from number to string. In my original suggestion I envisaged that Controller itself would be stateful (storing current-numeric-format for example) and be addressable from the buttons. But you seem to have ruled that out.
Your problem, as I see it, is that if you don't store this state somewhere then you have no way of telling the calculator to use anything other than a fixed* format for displaying any number entered. By fixed* I mean a very limited form of flexibility, such as always displaying the number of decimal digits that were in the most recently entered number, rather than absolutely fixed such as 12 digits, no more and no less.
At last I’ve found a nicer solution. I have added an inputHint property to the formatter object that takes care of the output formatting in the view. This input hint receives the value of the calculator input buffer and affects the formatting. If there is a decimal dot in the input hint, the formatter is forced to always keep the decimal dot in output, therefore solving the case of "0." being formatted as "0". And if the input contains some fraction digits, the formatter is forced to keep the same number of fraction digits in output (solves the case of "0.00" being formatted as "0").
I still have to expose the calculator input buffer and state, but I don’t have to expose the view’s display as string and don’t have to maintain the duplicate formatting code path for strings.

Resources