def test_with_modalities(self): data = Reader().read("./tests/data.txt") sentiment_data = Reader().read("./tests/sentiment_data.txt", fmt="UITup", sep=",", tup_sep=":") bm = BaseMethod.from_splits(train_data=data[:-1], test_data=data[-1:]) self.assertIsNone(bm.user_text) self.assertIsNone(bm.item_text) self.assertIsNone(bm.user_image) self.assertIsNone(bm.item_image) self.assertIsNone(bm.user_graph) self.assertIsNone(bm.item_graph) self.assertIsNone(bm.sentiment) bm.user_text = TextModality() bm.item_image = ImageModality() bm.sentiment = SentimentModality(data=sentiment_data) bm._build_modalities() try: bm.user_text = ImageModality() except ValueError: assert True try: bm.item_text = ImageModality() except ValueError: assert True try: bm.user_image = TextModality() except ValueError: assert True try: bm.item_image = TextModality() except ValueError: assert True try: bm.user_graph = TextModality() except ValueError: assert True try: bm.item_graph = ImageModality() except ValueError: assert True try: bm.sentiment = TextModality() except ValueError: assert True try: bm.sentiment = ImageModality() except ValueError: assert True
def batch_image(self): md = ImageModality() md.build(id_map=None) try: md.batch_image(batch_ids=None) except: raise NotImplementedError
def test_with_modalities(self): bm = BaseMethod() self.assertIsNone(bm.user_text) self.assertIsNone(bm.item_text) self.assertIsNone(bm.user_image) self.assertIsNone(bm.item_image) self.assertIsNone(bm.user_graph) self.assertIsNone(bm.item_graph) bm.user_text = TextModality() bm.item_image = ImageModality() bm._build_modalities() try: bm.user_text = ImageModality() except ValueError: assert True try: bm.item_text = ImageModality() except ValueError: assert True try: bm.user_image = TextModality() except ValueError: assert True try: bm.item_image = TextModality() except ValueError: assert True try: bm.user_graph = TextModality() except ValueError: assert True try: bm.item_graph = ImageModality() except ValueError: assert True
""" import cornac from cornac.datasets import tradesy from cornac.data import ImageModality from cornac.eval_methods import RatioSplit # VBPR extends Bayesian Personalized Randing to leverage item visual features (extracted from product images using CNN) # The necessary data can be loaded as follows feedback = tradesy.load_feedback() features, item_ids = tradesy.load_feature() # BIG file # Instantiate a ImageModality, it makes it convenient to work with visual auxiliary information # For more details, please refer to the tutorial on how to work with auxiliary data item_image_modality = ImageModality(features=features, ids=item_ids, normalized=True) # Define an evaluation method to split feedback into train and test sets ratio_split = RatioSplit( data=feedback, test_size=0.1, rating_threshold=0.5, exclude_unknowns=True, verbose=True, item_image=item_image_modality, ) # Instantiate CVAE vbpr = cornac.models.VBPR( k=10,
def test_init(self): md = ImageModality() md.build(id_map=None) self.assertIsNone(md.images) self.assertIsNone(md.paths)