Interrupt back-propagation in branched neural networks - keras

I've a neural network that looks something like this.
input_layer_1 input_layer_2
| |
| |
some_stuff some_other_stuff
| /|
| _________________/ |
| / |
multiply |
| |
| |
output_1 output_2
Is there any possibility to cut the connection between some_other_stuff and multiplyduring back-propagation? I was thinking of dropout but this also applied during forward-propagation
So during back-propagation it should be like two networks:
input_layer_1 input_layer_2
| |
| |
some_stuff some_other_stuff
| |
| |
| |
multiply |
| |
| |
output_1 output_2
Output_1 errors only influence weight adjustment in the left part of the network and Output_2 errors only on the right part.
I'm using keras with tensorflow so maybe there are some functions/Layers that achieve this.
Thanks.

If anyone wonders, you could use K.gradient_stop() inside a Lambda-Layer

Related

How to perform a series of steps in a single thread, with an async flow in spring-integration?

I currently have a spring-integration (v4.3.24) flow that looks like the following:
|
| list of
| filepaths
+----v---+
|splitter|
+----+---+
| filepath
|
+----------v----------+
|sftp-outbound-gateway|
| "get" |
+----------+----------+
| file
+---------------------+
| +----v----+ |
| |decryptor| |
| +----+----+ |
| | |
| +-----v------+ | set of transformers
| |decompressor| | (with routers before them
| +-----+------+ | because some steps are optional)
| | | that process the file;
| +--v--+ | call this "FileProcessor"
| | ... | |
| +--+--+ |
+---------------------+
|
+----v----+
|save file|
| to disk |
+----+----+
|
All of the channels above are DirectChannels - Yup, I know this is a poor structure. This was working fine for files in small numbers. But now, I have to deal with thousands of files which need to go through the same flow - benchmarks reveal that this takes ~ 1 day to finish processing. So, I'm planning to introduce some parallel processing to this flow. I want to modify my flow to achieve something like this:
|
|
+----------v----------+
|sftp-outbound-gateway|
| "mget" |
+----------+----------+
| list of files
|
+----v---+
|splitter|
+----+---+
one thread one | thread ...
+------------------------+---------------+--+--+--+--+
| file | file | | | | |
+---------------------+ +---------------------+
| +----v----+ | | +----v----+ |
| |decryptor| | | |decryptor| |
| +----+----+ | | +----+----+ |
| | | | | |
| +-----v------+ | | +-----v------+ | ...
| |decompressor| | | |decompressor| |
| +-----+------+ | | +-----+------+ |
| | | | | |
| +--v--+ | | +--v--+ |
| | ... | | | | ... | |
| +--+--+ | | +--+--+ |
+---------------------+ +---------------------+
| |
+----v----+ +----v----+
|save file| |save file|
| to disk | | to disk |
+----+----+ +----+----+
| |
| |
For parallel processing, I output the files from the splitter on to a ExecutorChannel with a ThreadPoolTaskExecutor.
Some of the questions that I have:
I want all of the "FileProcessor" steps for one file to happen on the same thread, while multiple files are processed in parallel. How can I achieve this?
I saw from this answer, that a ExecutorChannel to MessageHandlerChain flow would offer such functionality. But, some of the steps inside "FileProcessor" are optional (using selector-expression with routers to skip some of the steps) - ruling out using a MessageHandlerChain. I can rig up a couple of MessageHandlerChains with Filters inside, but this more or less becomes the approach mentioned in #2.
If #1 cannot be achieved, will changing all of the channel types starting from the splitter, from DirectChannel to ExecutorChannel help in introducing some parallelism? If yes, should I create a new TaskExecutor for each channel or can I reuse one TaskExecutor bean for all channels (I cannot set scope="prototype" on a TaskExecutor bean)?
In your opinion, which approach (#1 or #2) is better? Why?
If I perform global error handling, like the approach mentioned here, will the other files continue to process even if one file errors out?
It will work as you need by using an ExecutorChannel as an input to the decrypter and leave all the rest as direct channels; the remaining flow does not have to be a chain, each component will run on one of the executor's threads.
You will need to be sure all your downstream components are thread-safe.
Error handling should remain as is; each sub flow is independent.

How to translate syntatic parse to a dependency parse tree?

Using Link Grammar I can have the syntaxic parse of sentences something like the following:
+-------------------Xp------------------+
+------->WV------->+------Ost------+ |
+-----Wd----+ | +----Ds**x---+ |
| +Ds**c+--Ss--+ +-PHc+---A---+ |
| | | | | | | |
LEFT-WALL a koala.n is.v a cute.a animal.n .
+---------------------Xp--------------------+
+------->WV------>+---------Osm--------+ |
+-----Wd----+ | +------Ds**x------+ |
| +Ds**c+--Ss-+ +--PHc-+-----A----+ |
| | | | | | | |
LEFT-WALL a wolf.n is.v a dangerous.a animal.n .
+--------------------Xp--------------------+
+------->WV------>+--------Ost--------+ |
+-----Wd----+ | +------Ds**x-----+ |
| +Ds**c+--Ss-+ +--PHc-+----A----+ |
| | | | | | | |
LEFT-WALL a dog.n is.v a faithful.a animal.n .
+-----------------------Xp----------------------+
+------->WV------->+----------Osm----------+ |
+-----Wd----+ | +-------Ds**x-------+ |
| +Ds**c+--Ss--+ +--PHv--+-----A-----+ |
| | | | | | | |
LEFT-WALL a monkey.n is.v an independant.a animal.n .
The problem with this that it's not possible AFAIK to make sens
of that output programmatically; It seems like the way to go
is to convert that syntaxic output to a dependency parse tree
how can I achieve that?
You may want to look at RelEx (at GitHub).
From link-grammar at Wikipedia (emphasis mine):
The semantic relationship extractor RelEx, layered on top of the
Link Grammar library, generates a dependency grammar output by
making explicit the semantic relationships between words in a
sentence. Its output can be classified as being at a level between
that of SSyntR and DSyntR of Meaning-Text Theory. It also provides
framing/grounding, anaphora resolution, head-word identification,
lexical chunking, part-of-speech identification, and tagging,
including entity, date, money, gender, etc. tagging. It includes a
compatibility mode to generate dependency output compatible with
the Stanford parser, and Penn Treebank-compatible POS tagging.

Calc/Spreadsheet: combine/assign/migrate cols

Sorry, i can't use the right terms but i try to explain my task:
In Calc, or Spreadsheet I have two worksheets with columns like this:
| ID|
| 32|
| 51|
| 51|
| 63|
| 70|
and
| ID|Name |
| 01|name1 |
| 02|name2 |
...
| 69|name69 |
| 70|name70 |
i need to combine/assign/migrate these together, like:
| ID|Name |
| 32|name32 |
| 51|name51 |
| 51|name51 |
| 63|name63 |
| 70|name70 |
I have no idea how can is start to solve it. Please help!
Thank you #PsysicalChemist, the VLookup function is working in Calc to.

Resort key-Value combination

The following example just shows the pattern, my data much bigger.
I have a Table like
| Variable | String |
|:---------|-------:|
| V1 | Hello |
| V2 | little |
| V3 | World |
I have another table where different arrangements are defined
| Arrangement1 | Arrangement2 |
|:-------------|-------------:|
| V3 | V2 |
| V2 | V1 |
| V1 | V3 |
My output depending on the asked Arrangement (e.g. Arrangement1) should be
| Variable | Value |
|:---------|------:|
| V3 | World |
| V2 | little|
| V1 | Hello |
Till now I try to realize an approach with .find and array but think there might be an easier way (maybe with dictionary?) anyone an idea with good performance?

Write a command to increase or decrease the number of vertical splits

I usually have my Vim screen split into two vertical windows, each of which may be further horizontally split. Sometimes, I want to add or delete a vertical window. Is there a way to detect how many top-level vertical splits there are and add or remove vsplits as necessary?
For example, suppose my screen looks like this:
+--------+--------+
| | |
| | |
+--------+ |
| | |
| | |
| +--------+
| | |
+--------+--------+
I want :Columns 1 to give me
+--------+
| |
| |
+--------+
| |
| |
| |
| |
+--------+
by closing the two right-most windows.
I want :Columns 2 to do nothing, detecting that two columns are already open.
And I want :Columns 3 to give me
+--------+--------+--------+
| | | |
| | | |
+--------+ | |
| | | |
| | | |
| +--------+ |
| | | |
+--------+--------+--------+
I am fine if the function ignores vertical splits within horizontal splits. For example, if I had
+--------+
| |
| |
+---+----+
| | |
| | |
| | |
| | |
+---+----+
and I ran :Columns 2, I would get
+--------+--------+
| | |
| | |
+---+----+ |
| | | |
| | | |
| | | |
| | | |
+---+----+--------+
There is indeed a way, but it is involved; the first step is to count the currently-open vertical windows, and I don’t know of any built-in function that facilitates this. The working approach I found to it is basically to start at the first window (the top of the first — if not the entirety of the first — vertical split), and to then, using wincmd l, move to the next window to the right for as long as wincmd l moves to a new window, adding each to a count of open vertical windows including the first one. (I think this is what Gary Fixler referred to in the comments on the question.)
I started trying to write the code for posting here, and it grew to become larger than any function I would want to put in my ~/.vimrc, so I ended up turning it into a plugin which takes the above approach and provides the :Columns command; see Columcille (on vim.org at http://www.vim.org/scripts/script.php?script_id=4742.) The plugin also provides a command for similarly managing horizontal split windows: :Rows divides the current column (or the main window, if there are no open vertical splits) into the specified number of “rows.”

Resources