Coder Social home page Coder Social logo

Comments (2)

n0obcoder avatar n0obcoder commented on June 11, 2024

i noticed that this error is occuring when all the 500 test examples are yielded and there is calling the next() method on this causes this error. But i still don't know how can i resolve this error.

from sequence-based-recommendations.

n0obcoder avatar n0obcoder commented on June 11, 2024

i fixed it by the help of https://stackoverflow.com/questions/51700960/runtimeerror-generator-raised-stopiteration-every-time-i-try-to-run-app

i changed

while True:
	j = 0
	sequences = []
	batch_size = self.batch_size
	if test:
		batch_size = 1
	while j < batch_size:
		
		sequence, user_id = next(sequence_generator)

		# print('sequence: ', sequence)
		# print('user_id: ', user_id, 'test: ', test)
		# pdb.set_trace()

		# finds the lengths of the different subsequences
		if not test:
			seq_lengths = sorted(random.sample(range(2, len(sequence)), min([batch_size - j, len(sequence) - 2, max_reuse_sequence])))
		else:
			seq_lengths = [int(len(sequence) / 2)] 

		skipped_seq = 0
		for l in seq_lengths:
			target = self.target_selection(sequence[l:], test=test)
			if len(target) == 0:
				skipped_seq += 1
				continue
			start = max(0, l - self.max_length) # sequences cannot be longer than self.max_lenght
			sequences.append([user_id, sequence[start:l], target])

		j += len(seq_lengths) - skipped_seq

	if test:
		# sequence[seq_lengths[0]:] is the sequence (ratings included) GT here
		# [i[0] for i in sequence[seq_lengths[0]:]]  is the GT here (ratings excluded)
		yield self._prepare_input(sequences), [i[0] for i in sequence[seq_lengths[0]:]] 
	else:
		yield self._prepare_input(sequences)

to

while True:
	try:
		j = 0
		sequences = []
		batch_size = self.batch_size
		if test:
			batch_size = 1
		while j < batch_size:
			
			sequence, user_id = next(sequence_generator)

			# print('sequence: ', sequence)
			# print('user_id: ', user_id, 'test: ', test)
			# pdb.set_trace()

			# finds the lengths of the different subsequences
			if not test:
				seq_lengths = sorted(random.sample(range(2, len(sequence)), min([batch_size - j, len(sequence) - 2, max_reuse_sequence])))
			else:
				seq_lengths = [int(len(sequence) / 2)] 

			skipped_seq = 0
			for l in seq_lengths:
				target = self.target_selection(sequence[l:], test=test)
				if len(target) == 0:
					skipped_seq += 1
					continue
				start = max(0, l - self.max_length) # sequences cannot be longer than self.max_lenght
				sequences.append([user_id, sequence[start:l], target])

			j += len(seq_lengths) - skipped_seq

		if test:
			# sequence[seq_lengths[0]:] is the sequence (ratings included) GT here
			# [i[0] for i in sequence[seq_lengths[0]:]]  is the GT here (ratings excluded)
			yield self._prepare_input(sequences), [i[0] for i in sequence[seq_lengths[0]:]] 
		else:
			yield self._prepare_input(sequences)
	except StopIteration:
		return

from sequence-based-recommendations.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.