Encoding and Decoding Representations with Sum- and Max-Product Networks